Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Afatech AF9033 demodulator driver |
| 3 | * |
| 4 | * Copyright (C) 2009 Antti Palosaari <crope@iki.fi> |
| 5 | * Copyright (C) 2012 Antti Palosaari <crope@iki.fi> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #include "af9033_priv.h" |
| 23 | |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 24 | /* Max transfer size done by I2C transfer functions */ |
| 25 | #define MAX_XFER_SIZE 64 |
| 26 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 27 | struct af9033_dev { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 28 | struct i2c_adapter *i2c; |
| 29 | struct dvb_frontend fe; |
| 30 | struct af9033_config cfg; |
| 31 | |
| 32 | u32 bandwidth_hz; |
| 33 | bool ts_mode_parallel; |
| 34 | bool ts_mode_serial; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 35 | |
| 36 | u32 ber; |
| 37 | u32 ucb; |
| 38 | unsigned long last_stat_check; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | /* write multiple registers */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 42 | static int af9033_wr_regs(struct af9033_dev *dev, u32 reg, const u8 *val, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 43 | int len) |
| 44 | { |
| 45 | int ret; |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 46 | u8 buf[MAX_XFER_SIZE]; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 47 | struct i2c_msg msg[1] = { |
| 48 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 49 | .addr = dev->cfg.i2c_addr, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 50 | .flags = 0, |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 51 | .len = 3 + len, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 52 | .buf = buf, |
| 53 | } |
| 54 | }; |
| 55 | |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 56 | if (3 + len > sizeof(buf)) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 57 | dev_warn(&dev->i2c->dev, |
Mauro Carvalho Chehab | 37ebaf6 | 2013-11-02 05:11:47 -0300 | [diff] [blame] | 58 | "%s: i2c wr reg=%04x: len=%d is too big!\n", |
| 59 | KBUILD_MODNAME, reg, len); |
| 60 | return -EINVAL; |
| 61 | } |
| 62 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 63 | buf[0] = (reg >> 16) & 0xff; |
| 64 | buf[1] = (reg >> 8) & 0xff; |
| 65 | buf[2] = (reg >> 0) & 0xff; |
| 66 | memcpy(&buf[3], val, len); |
| 67 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 68 | ret = i2c_transfer(dev->i2c, msg, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 69 | if (ret == 1) { |
| 70 | ret = 0; |
| 71 | } else { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 72 | dev_warn(&dev->i2c->dev, |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 73 | "%s: i2c wr failed=%d reg=%06x len=%d\n", |
| 74 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 75 | ret = -EREMOTEIO; |
| 76 | } |
| 77 | |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | /* read multiple registers */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 82 | static int af9033_rd_regs(struct af9033_dev *dev, u32 reg, u8 *val, int len) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 83 | { |
| 84 | int ret; |
| 85 | u8 buf[3] = { (reg >> 16) & 0xff, (reg >> 8) & 0xff, |
| 86 | (reg >> 0) & 0xff }; |
| 87 | struct i2c_msg msg[2] = { |
| 88 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 89 | .addr = dev->cfg.i2c_addr, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 90 | .flags = 0, |
| 91 | .len = sizeof(buf), |
| 92 | .buf = buf |
| 93 | }, { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 94 | .addr = dev->cfg.i2c_addr, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 95 | .flags = I2C_M_RD, |
| 96 | .len = len, |
| 97 | .buf = val |
| 98 | } |
| 99 | }; |
| 100 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 101 | ret = i2c_transfer(dev->i2c, msg, 2); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 102 | if (ret == 2) { |
| 103 | ret = 0; |
| 104 | } else { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 105 | dev_warn(&dev->i2c->dev, |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 106 | "%s: i2c rd failed=%d reg=%06x len=%d\n", |
| 107 | KBUILD_MODNAME, ret, reg, len); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 108 | ret = -EREMOTEIO; |
| 109 | } |
| 110 | |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | /* write single register */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 116 | static int af9033_wr_reg(struct af9033_dev *dev, u32 reg, u8 val) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 117 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 118 | return af9033_wr_regs(dev, reg, &val, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | /* read single register */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 122 | static int af9033_rd_reg(struct af9033_dev *dev, u32 reg, u8 *val) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 123 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 124 | return af9033_rd_regs(dev, reg, val, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | /* write single register with mask */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 128 | static int af9033_wr_reg_mask(struct af9033_dev *dev, u32 reg, u8 val, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 129 | u8 mask) |
| 130 | { |
| 131 | int ret; |
| 132 | u8 tmp; |
| 133 | |
| 134 | /* no need for read if whole reg is written */ |
| 135 | if (mask != 0xff) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 136 | ret = af9033_rd_regs(dev, reg, &tmp, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 137 | if (ret) |
| 138 | return ret; |
| 139 | |
| 140 | val &= mask; |
| 141 | tmp &= ~mask; |
| 142 | val |= tmp; |
| 143 | } |
| 144 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 145 | return af9033_wr_regs(dev, reg, &val, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* read single register with mask */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 149 | static int af9033_rd_reg_mask(struct af9033_dev *dev, u32 reg, u8 *val, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 150 | u8 mask) |
| 151 | { |
| 152 | int ret, i; |
| 153 | u8 tmp; |
| 154 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 155 | ret = af9033_rd_regs(dev, reg, &tmp, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 156 | if (ret) |
| 157 | return ret; |
| 158 | |
| 159 | tmp &= mask; |
| 160 | |
| 161 | /* find position of the first bit */ |
| 162 | for (i = 0; i < 8; i++) { |
| 163 | if ((mask >> i) & 0x01) |
| 164 | break; |
| 165 | } |
| 166 | *val = tmp >> i; |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 171 | /* write reg val table using reg addr auto increment */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 172 | static int af9033_wr_reg_val_tab(struct af9033_dev *dev, |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 173 | const struct reg_val *tab, int tab_len) |
| 174 | { |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 175 | #define MAX_TAB_LEN 212 |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 176 | int ret, i, j; |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 177 | u8 buf[1 + MAX_TAB_LEN]; |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 178 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 179 | dev_dbg(&dev->i2c->dev, "%s: tab_len=%d\n", __func__, tab_len); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 180 | |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 181 | if (tab_len > sizeof(buf)) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 182 | dev_warn(&dev->i2c->dev, "%s: tab len %d is too big\n", |
Antti Palosaari | d18a88b | 2013-11-27 17:17:43 -0300 | [diff] [blame] | 183 | KBUILD_MODNAME, tab_len); |
| 184 | return -EINVAL; |
| 185 | } |
| 186 | |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 187 | for (i = 0, j = 0; i < tab_len; i++) { |
| 188 | buf[j] = tab[i].val; |
| 189 | |
| 190 | if (i == tab_len - 1 || tab[i].reg != tab[i + 1].reg - 1) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 191 | ret = af9033_wr_regs(dev, tab[i].reg - j, buf, j + 1); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 192 | if (ret < 0) |
| 193 | goto err; |
| 194 | |
| 195 | j = 0; |
| 196 | } else { |
| 197 | j++; |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | return 0; |
| 202 | |
| 203 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 204 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 205 | |
| 206 | return ret; |
| 207 | } |
| 208 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 209 | static u32 af9033_div(struct af9033_dev *dev, u32 a, u32 b, u32 x) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 210 | { |
| 211 | u32 r = 0, c = 0, i; |
| 212 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 213 | dev_dbg(&dev->i2c->dev, "%s: a=%d b=%d x=%d\n", __func__, a, b, x); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 214 | |
| 215 | if (a > b) { |
| 216 | c = a / b; |
| 217 | a = a - c * b; |
| 218 | } |
| 219 | |
| 220 | for (i = 0; i < x; i++) { |
| 221 | if (a >= b) { |
| 222 | r += 1; |
| 223 | a -= b; |
| 224 | } |
| 225 | a <<= 1; |
| 226 | r <<= 1; |
| 227 | } |
| 228 | r = (c << (u32)x) + r; |
| 229 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 230 | dev_dbg(&dev->i2c->dev, "%s: a=%d b=%d x=%d r=%d r=%x\n", |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 231 | __func__, a, b, x, r, r); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 232 | |
| 233 | return r; |
| 234 | } |
| 235 | |
| 236 | static void af9033_release(struct dvb_frontend *fe) |
| 237 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 238 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 239 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 240 | kfree(dev); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | static int af9033_init(struct dvb_frontend *fe) |
| 244 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 245 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 246 | int ret, i, len; |
| 247 | const struct reg_val *init; |
| 248 | u8 buf[4]; |
| 249 | u32 adc_cw, clock_cw; |
| 250 | struct reg_val_mask tab[] = { |
| 251 | { 0x80fb24, 0x00, 0x08 }, |
| 252 | { 0x80004c, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 253 | { 0x00f641, dev->cfg.tuner, 0xff }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 254 | { 0x80f5ca, 0x01, 0x01 }, |
| 255 | { 0x80f715, 0x01, 0x01 }, |
| 256 | { 0x00f41f, 0x04, 0x04 }, |
| 257 | { 0x00f41a, 0x01, 0x01 }, |
| 258 | { 0x80f731, 0x00, 0x01 }, |
| 259 | { 0x00d91e, 0x00, 0x01 }, |
| 260 | { 0x00d919, 0x00, 0x01 }, |
| 261 | { 0x80f732, 0x00, 0x01 }, |
| 262 | { 0x00d91f, 0x00, 0x01 }, |
| 263 | { 0x00d91a, 0x00, 0x01 }, |
| 264 | { 0x80f730, 0x00, 0x01 }, |
| 265 | { 0x80f778, 0x00, 0xff }, |
| 266 | { 0x80f73c, 0x01, 0x01 }, |
| 267 | { 0x80f776, 0x00, 0x01 }, |
| 268 | { 0x00d8fd, 0x01, 0xff }, |
| 269 | { 0x00d830, 0x01, 0xff }, |
| 270 | { 0x00d831, 0x00, 0xff }, |
| 271 | { 0x00d832, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 272 | { 0x80f985, dev->ts_mode_serial, 0x01 }, |
| 273 | { 0x80f986, dev->ts_mode_parallel, 0x01 }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 274 | { 0x00d827, 0x00, 0xff }, |
| 275 | { 0x00d829, 0x00, 0xff }, |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 276 | { 0x800045, dev->cfg.adc_multiplier, 0xff }, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | /* program clock control */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 280 | clock_cw = af9033_div(dev, dev->cfg.clock, 1000000ul, 19ul); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 281 | buf[0] = (clock_cw >> 0) & 0xff; |
| 282 | buf[1] = (clock_cw >> 8) & 0xff; |
| 283 | buf[2] = (clock_cw >> 16) & 0xff; |
| 284 | buf[3] = (clock_cw >> 24) & 0xff; |
| 285 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 286 | dev_dbg(&dev->i2c->dev, "%s: clock=%d clock_cw=%08x\n", |
| 287 | __func__, dev->cfg.clock, clock_cw); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 288 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 289 | ret = af9033_wr_regs(dev, 0x800025, buf, 4); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 290 | if (ret < 0) |
| 291 | goto err; |
| 292 | |
| 293 | /* program ADC control */ |
| 294 | for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 295 | if (clock_adc_lut[i].clock == dev->cfg.clock) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 296 | break; |
| 297 | } |
| 298 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 299 | adc_cw = af9033_div(dev, clock_adc_lut[i].adc, 1000000ul, 19ul); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 300 | buf[0] = (adc_cw >> 0) & 0xff; |
| 301 | buf[1] = (adc_cw >> 8) & 0xff; |
| 302 | buf[2] = (adc_cw >> 16) & 0xff; |
| 303 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 304 | dev_dbg(&dev->i2c->dev, "%s: adc=%d adc_cw=%06x\n", |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 305 | __func__, clock_adc_lut[i].adc, adc_cw); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 306 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 307 | ret = af9033_wr_regs(dev, 0x80f1cd, buf, 3); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 308 | if (ret < 0) |
| 309 | goto err; |
| 310 | |
| 311 | /* program register table */ |
| 312 | for (i = 0; i < ARRAY_SIZE(tab); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 313 | ret = af9033_wr_reg_mask(dev, tab[i].reg, tab[i].val, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 314 | tab[i].mask); |
| 315 | if (ret < 0) |
| 316 | goto err; |
| 317 | } |
| 318 | |
Antti Palosaari | ca681fe | 2014-08-08 23:56:49 -0300 | [diff] [blame] | 319 | /* clock output */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 320 | if (dev->cfg.dyn0_clk) { |
| 321 | ret = af9033_wr_reg(dev, 0x80fba8, 0x00); |
Antti Palosaari | 9dc0f3f | 2014-08-09 01:03:14 -0300 | [diff] [blame] | 322 | if (ret < 0) |
| 323 | goto err; |
| 324 | } |
| 325 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 326 | /* settings for TS interface */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 327 | if (dev->cfg.ts_mode == AF9033_TS_MODE_USB) { |
| 328 | ret = af9033_wr_reg_mask(dev, 0x80f9a5, 0x00, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 329 | if (ret < 0) |
| 330 | goto err; |
| 331 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 332 | ret = af9033_wr_reg_mask(dev, 0x80f9b5, 0x01, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 333 | if (ret < 0) |
| 334 | goto err; |
| 335 | } else { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 336 | ret = af9033_wr_reg_mask(dev, 0x80f990, 0x00, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 337 | if (ret < 0) |
| 338 | goto err; |
| 339 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 340 | ret = af9033_wr_reg_mask(dev, 0x80f9b5, 0x00, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 341 | if (ret < 0) |
| 342 | goto err; |
| 343 | } |
| 344 | |
| 345 | /* load OFSM settings */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 346 | dev_dbg(&dev->i2c->dev, "%s: load ofsm settings\n", __func__); |
| 347 | switch (dev->cfg.tuner) { |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 348 | case AF9033_TUNER_IT9135_38: |
| 349 | case AF9033_TUNER_IT9135_51: |
| 350 | case AF9033_TUNER_IT9135_52: |
Antti Palosaari | 463c399 | 2013-03-07 00:03:06 -0300 | [diff] [blame] | 351 | len = ARRAY_SIZE(ofsm_init_it9135_v1); |
| 352 | init = ofsm_init_it9135_v1; |
| 353 | break; |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 354 | case AF9033_TUNER_IT9135_60: |
| 355 | case AF9033_TUNER_IT9135_61: |
| 356 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | 463c399 | 2013-03-07 00:03:06 -0300 | [diff] [blame] | 357 | len = ARRAY_SIZE(ofsm_init_it9135_v2); |
| 358 | init = ofsm_init_it9135_v2; |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 359 | break; |
| 360 | default: |
| 361 | len = ARRAY_SIZE(ofsm_init); |
| 362 | init = ofsm_init; |
| 363 | break; |
| 364 | } |
| 365 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 366 | ret = af9033_wr_reg_val_tab(dev, init, len); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 367 | if (ret < 0) |
| 368 | goto err; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 369 | |
| 370 | /* load tuner specific settings */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 371 | dev_dbg(&dev->i2c->dev, "%s: load tuner specific settings\n", |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 372 | __func__); |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 373 | switch (dev->cfg.tuner) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 374 | case AF9033_TUNER_TUA9001: |
| 375 | len = ARRAY_SIZE(tuner_init_tua9001); |
| 376 | init = tuner_init_tua9001; |
| 377 | break; |
Michael Büsch | ffc501f | 2012-04-02 12:18:36 -0300 | [diff] [blame] | 378 | case AF9033_TUNER_FC0011: |
| 379 | len = ARRAY_SIZE(tuner_init_fc0011); |
| 380 | init = tuner_init_fc0011; |
| 381 | break; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 382 | case AF9033_TUNER_MXL5007T: |
| 383 | len = ARRAY_SIZE(tuner_init_mxl5007t); |
| 384 | init = tuner_init_mxl5007t; |
| 385 | break; |
Gianluca Gennari | ce1fe37 | 2012-04-02 17:25:14 -0300 | [diff] [blame] | 386 | case AF9033_TUNER_TDA18218: |
| 387 | len = ARRAY_SIZE(tuner_init_tda18218); |
| 388 | init = tuner_init_tda18218; |
| 389 | break; |
Oliver Schinagl | d67ceb3 | 2012-09-20 14:57:17 -0300 | [diff] [blame] | 390 | case AF9033_TUNER_FC2580: |
| 391 | len = ARRAY_SIZE(tuner_init_fc2580); |
| 392 | init = tuner_init_fc2580; |
| 393 | break; |
Antti Palosaari | e713ad1 | 2012-12-02 18:47:00 -0300 | [diff] [blame] | 394 | case AF9033_TUNER_FC0012: |
| 395 | len = ARRAY_SIZE(tuner_init_fc0012); |
| 396 | init = tuner_init_fc0012; |
| 397 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 398 | case AF9033_TUNER_IT9135_38: |
Antti Palosaari | a72cbb7 | 2013-03-07 21:17:55 -0300 | [diff] [blame] | 399 | len = ARRAY_SIZE(tuner_init_it9135_38); |
| 400 | init = tuner_init_it9135_38; |
| 401 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 402 | case AF9033_TUNER_IT9135_51: |
Antti Palosaari | bb2e12a | 2013-03-07 21:25:16 -0300 | [diff] [blame] | 403 | len = ARRAY_SIZE(tuner_init_it9135_51); |
| 404 | init = tuner_init_it9135_51; |
| 405 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 406 | case AF9033_TUNER_IT9135_52: |
Antti Palosaari | 22d729f | 2013-03-07 21:29:05 -0300 | [diff] [blame] | 407 | len = ARRAY_SIZE(tuner_init_it9135_52); |
| 408 | init = tuner_init_it9135_52; |
| 409 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 410 | case AF9033_TUNER_IT9135_60: |
Antti Palosaari | a49f53a | 2013-03-07 21:38:00 -0300 | [diff] [blame] | 411 | len = ARRAY_SIZE(tuner_init_it9135_60); |
| 412 | init = tuner_init_it9135_60; |
| 413 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 414 | case AF9033_TUNER_IT9135_61: |
Antti Palosaari | 8521132 | 2013-03-07 21:44:30 -0300 | [diff] [blame] | 415 | len = ARRAY_SIZE(tuner_init_it9135_61); |
| 416 | init = tuner_init_it9135_61; |
| 417 | break; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 418 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | dc4a2c4 | 2013-03-07 21:47:20 -0300 | [diff] [blame] | 419 | len = ARRAY_SIZE(tuner_init_it9135_62); |
| 420 | init = tuner_init_it9135_62; |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 421 | break; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 422 | default: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 423 | dev_dbg(&dev->i2c->dev, "%s: unsupported tuner ID=%d\n", |
| 424 | __func__, dev->cfg.tuner); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 425 | ret = -ENODEV; |
| 426 | goto err; |
| 427 | } |
| 428 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 429 | ret = af9033_wr_reg_val_tab(dev, init, len); |
Antti Palosaari | 3bf5e55 | 2013-03-08 16:54:09 -0300 | [diff] [blame] | 430 | if (ret < 0) |
| 431 | goto err; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 432 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 433 | if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) { |
| 434 | ret = af9033_wr_reg_mask(dev, 0x00d91c, 0x01, 0x01); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 435 | if (ret < 0) |
| 436 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 437 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 438 | ret = af9033_wr_reg_mask(dev, 0x00d917, 0x00, 0x01); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 439 | if (ret < 0) |
| 440 | goto err; |
Antti Palosaari | bf97b63 | 2012-12-08 22:51:19 -0300 | [diff] [blame] | 441 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 442 | ret = af9033_wr_reg_mask(dev, 0x00d916, 0x00, 0x01); |
Jose Alberto Reguero | 9805992 | 2012-09-23 16:48:47 -0300 | [diff] [blame] | 443 | if (ret < 0) |
| 444 | goto err; |
| 445 | } |
| 446 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 447 | switch (dev->cfg.tuner) { |
Antti Palosaari | 086991d | 2013-03-07 22:18:56 -0300 | [diff] [blame] | 448 | case AF9033_TUNER_IT9135_60: |
| 449 | case AF9033_TUNER_IT9135_61: |
| 450 | case AF9033_TUNER_IT9135_62: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 451 | ret = af9033_wr_reg(dev, 0x800000, 0x01); |
Antti Palosaari | 086991d | 2013-03-07 22:18:56 -0300 | [diff] [blame] | 452 | if (ret < 0) |
| 453 | goto err; |
| 454 | } |
| 455 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 456 | dev->bandwidth_hz = 0; /* force to program all parameters */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 457 | |
| 458 | return 0; |
| 459 | |
| 460 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 461 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 462 | |
| 463 | return ret; |
| 464 | } |
| 465 | |
| 466 | static int af9033_sleep(struct dvb_frontend *fe) |
| 467 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 468 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 469 | int ret, i; |
| 470 | u8 tmp; |
| 471 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 472 | ret = af9033_wr_reg(dev, 0x80004c, 1); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 473 | if (ret < 0) |
| 474 | goto err; |
| 475 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 476 | ret = af9033_wr_reg(dev, 0x800000, 0); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 477 | if (ret < 0) |
| 478 | goto err; |
| 479 | |
| 480 | for (i = 100, tmp = 1; i && tmp; i--) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 481 | ret = af9033_rd_reg(dev, 0x80004c, &tmp); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 482 | if (ret < 0) |
| 483 | goto err; |
| 484 | |
| 485 | usleep_range(200, 10000); |
| 486 | } |
| 487 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 488 | dev_dbg(&dev->i2c->dev, "%s: loop=%d\n", __func__, i); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 489 | |
| 490 | if (i == 0) { |
| 491 | ret = -ETIMEDOUT; |
| 492 | goto err; |
| 493 | } |
| 494 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 495 | ret = af9033_wr_reg_mask(dev, 0x80fb24, 0x08, 0x08); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 496 | if (ret < 0) |
| 497 | goto err; |
| 498 | |
| 499 | /* prevent current leak (?) */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 500 | if (dev->cfg.ts_mode == AF9033_TS_MODE_SERIAL) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 501 | /* enable parallel TS */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 502 | ret = af9033_wr_reg_mask(dev, 0x00d917, 0x00, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 503 | if (ret < 0) |
| 504 | goto err; |
| 505 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 506 | ret = af9033_wr_reg_mask(dev, 0x00d916, 0x01, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 507 | if (ret < 0) |
| 508 | goto err; |
| 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | |
| 513 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 514 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 515 | |
| 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | static int af9033_get_tune_settings(struct dvb_frontend *fe, |
| 520 | struct dvb_frontend_tune_settings *fesettings) |
| 521 | { |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 522 | /* 800 => 2000 because IT9135 v2 is slow to gain lock */ |
| 523 | fesettings->min_delay_ms = 2000; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 524 | fesettings->step_size = 0; |
| 525 | fesettings->max_drift = 0; |
| 526 | |
| 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | static int af9033_set_frontend(struct dvb_frontend *fe) |
| 531 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 532 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 533 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 534 | int ret, i, spec_inv, sampling_freq; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 535 | u8 tmp, buf[3], bandwidth_reg_val; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 536 | u32 if_frequency, freq_cw, adc_freq; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 537 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 538 | dev_dbg(&dev->i2c->dev, "%s: frequency=%d bandwidth_hz=%d\n", |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 539 | __func__, c->frequency, c->bandwidth_hz); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 540 | |
| 541 | /* check bandwidth */ |
| 542 | switch (c->bandwidth_hz) { |
| 543 | case 6000000: |
| 544 | bandwidth_reg_val = 0x00; |
| 545 | break; |
| 546 | case 7000000: |
| 547 | bandwidth_reg_val = 0x01; |
| 548 | break; |
| 549 | case 8000000: |
| 550 | bandwidth_reg_val = 0x02; |
| 551 | break; |
| 552 | default: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 553 | dev_dbg(&dev->i2c->dev, "%s: invalid bandwidth_hz\n", |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 554 | __func__); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 555 | ret = -EINVAL; |
| 556 | goto err; |
| 557 | } |
| 558 | |
| 559 | /* program tuner */ |
| 560 | if (fe->ops.tuner_ops.set_params) |
| 561 | fe->ops.tuner_ops.set_params(fe); |
| 562 | |
| 563 | /* program CFOE coefficients */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 564 | if (c->bandwidth_hz != dev->bandwidth_hz) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 565 | for (i = 0; i < ARRAY_SIZE(coeff_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 566 | if (coeff_lut[i].clock == dev->cfg.clock && |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 567 | coeff_lut[i].bandwidth_hz == c->bandwidth_hz) { |
| 568 | break; |
| 569 | } |
| 570 | } |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 571 | ret = af9033_wr_regs(dev, 0x800001, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 572 | coeff_lut[i].val, sizeof(coeff_lut[i].val)); |
| 573 | } |
| 574 | |
| 575 | /* program frequency control */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 576 | if (c->bandwidth_hz != dev->bandwidth_hz) { |
| 577 | spec_inv = dev->cfg.spec_inv ? -1 : 1; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 578 | |
| 579 | for (i = 0; i < ARRAY_SIZE(clock_adc_lut); i++) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 580 | if (clock_adc_lut[i].clock == dev->cfg.clock) |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 581 | break; |
| 582 | } |
| 583 | adc_freq = clock_adc_lut[i].adc; |
| 584 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 585 | /* get used IF frequency */ |
| 586 | if (fe->ops.tuner_ops.get_if_frequency) |
| 587 | fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency); |
| 588 | else |
| 589 | if_frequency = 0; |
| 590 | |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 591 | sampling_freq = if_frequency; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 592 | |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 593 | while (sampling_freq > (adc_freq / 2)) |
| 594 | sampling_freq -= adc_freq; |
| 595 | |
| 596 | if (sampling_freq >= 0) |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 597 | spec_inv *= -1; |
| 598 | else |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 599 | sampling_freq *= -1; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 600 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 601 | freq_cw = af9033_div(dev, sampling_freq, adc_freq, 23ul); |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 602 | |
| 603 | if (spec_inv == -1) |
Hans-Frieder Vogt | 182b967 | 2012-10-03 05:25:40 -0300 | [diff] [blame] | 604 | freq_cw = 0x800000 - freq_cw; |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 605 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 606 | if (dev->cfg.adc_multiplier == AF9033_ADC_MULTIPLIER_2X) |
Hans-Frieder Vogt | 540fd4b | 2012-04-02 14:18:16 -0300 | [diff] [blame] | 607 | freq_cw /= 2; |
| 608 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 609 | buf[0] = (freq_cw >> 0) & 0xff; |
| 610 | buf[1] = (freq_cw >> 8) & 0xff; |
| 611 | buf[2] = (freq_cw >> 16) & 0x7f; |
Antti Palosaari | fe8eece | 2013-02-03 13:39:55 -0300 | [diff] [blame] | 612 | |
| 613 | /* FIXME: there seems to be calculation error here... */ |
| 614 | if (if_frequency == 0) |
| 615 | buf[2] = 0; |
| 616 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 617 | ret = af9033_wr_regs(dev, 0x800029, buf, 3); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 618 | if (ret < 0) |
| 619 | goto err; |
| 620 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 621 | dev->bandwidth_hz = c->bandwidth_hz; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 622 | } |
| 623 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 624 | ret = af9033_wr_reg_mask(dev, 0x80f904, bandwidth_reg_val, 0x03); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 625 | if (ret < 0) |
| 626 | goto err; |
| 627 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 628 | ret = af9033_wr_reg(dev, 0x800040, 0x00); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 629 | if (ret < 0) |
| 630 | goto err; |
| 631 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 632 | ret = af9033_wr_reg(dev, 0x800047, 0x00); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 633 | if (ret < 0) |
| 634 | goto err; |
| 635 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 636 | ret = af9033_wr_reg_mask(dev, 0x80f999, 0x00, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 637 | if (ret < 0) |
| 638 | goto err; |
| 639 | |
| 640 | if (c->frequency <= 230000000) |
| 641 | tmp = 0x00; /* VHF */ |
| 642 | else |
| 643 | tmp = 0x01; /* UHF */ |
| 644 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 645 | ret = af9033_wr_reg(dev, 0x80004b, tmp); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 646 | if (ret < 0) |
| 647 | goto err; |
| 648 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 649 | ret = af9033_wr_reg(dev, 0x800000, 0x00); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 650 | if (ret < 0) |
| 651 | goto err; |
| 652 | |
| 653 | return 0; |
| 654 | |
| 655 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 656 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 657 | |
| 658 | return ret; |
| 659 | } |
| 660 | |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 661 | static int af9033_get_frontend(struct dvb_frontend *fe) |
| 662 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 663 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 664 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 665 | int ret; |
| 666 | u8 buf[8]; |
| 667 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 668 | dev_dbg(&dev->i2c->dev, "%s:\n", __func__); |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 669 | |
| 670 | /* read all needed registers */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 671 | ret = af9033_rd_regs(dev, 0x80f900, buf, sizeof(buf)); |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 672 | if (ret < 0) |
| 673 | goto err; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 674 | |
| 675 | switch ((buf[0] >> 0) & 3) { |
| 676 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 677 | c->transmission_mode = TRANSMISSION_MODE_2K; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 678 | break; |
| 679 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 680 | c->transmission_mode = TRANSMISSION_MODE_8K; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 681 | break; |
| 682 | } |
| 683 | |
| 684 | switch ((buf[1] >> 0) & 3) { |
| 685 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 686 | c->guard_interval = GUARD_INTERVAL_1_32; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 687 | break; |
| 688 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 689 | c->guard_interval = GUARD_INTERVAL_1_16; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 690 | break; |
| 691 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 692 | c->guard_interval = GUARD_INTERVAL_1_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 693 | break; |
| 694 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 695 | c->guard_interval = GUARD_INTERVAL_1_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 696 | break; |
| 697 | } |
| 698 | |
| 699 | switch ((buf[2] >> 0) & 7) { |
| 700 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 701 | c->hierarchy = HIERARCHY_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 702 | break; |
| 703 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 704 | c->hierarchy = HIERARCHY_1; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 705 | break; |
| 706 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 707 | c->hierarchy = HIERARCHY_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 708 | break; |
| 709 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 710 | c->hierarchy = HIERARCHY_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 711 | break; |
| 712 | } |
| 713 | |
| 714 | switch ((buf[3] >> 0) & 3) { |
| 715 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 716 | c->modulation = QPSK; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 717 | break; |
| 718 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 719 | c->modulation = QAM_16; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 720 | break; |
| 721 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 722 | c->modulation = QAM_64; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 723 | break; |
| 724 | } |
| 725 | |
| 726 | switch ((buf[4] >> 0) & 3) { |
| 727 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 728 | c->bandwidth_hz = 6000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 729 | break; |
| 730 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 731 | c->bandwidth_hz = 7000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 732 | break; |
| 733 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 734 | c->bandwidth_hz = 8000000; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | |
| 738 | switch ((buf[6] >> 0) & 7) { |
| 739 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 740 | c->code_rate_HP = FEC_1_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 741 | break; |
| 742 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 743 | c->code_rate_HP = FEC_2_3; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 744 | break; |
| 745 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 746 | c->code_rate_HP = FEC_3_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 747 | break; |
| 748 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 749 | c->code_rate_HP = FEC_5_6; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 750 | break; |
| 751 | case 4: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 752 | c->code_rate_HP = FEC_7_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 753 | break; |
| 754 | case 5: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 755 | c->code_rate_HP = FEC_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 756 | break; |
| 757 | } |
| 758 | |
| 759 | switch ((buf[7] >> 0) & 7) { |
| 760 | case 0: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 761 | c->code_rate_LP = FEC_1_2; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 762 | break; |
| 763 | case 1: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 764 | c->code_rate_LP = FEC_2_3; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 765 | break; |
| 766 | case 2: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 767 | c->code_rate_LP = FEC_3_4; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 768 | break; |
| 769 | case 3: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 770 | c->code_rate_LP = FEC_5_6; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 771 | break; |
| 772 | case 4: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 773 | c->code_rate_LP = FEC_7_8; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 774 | break; |
| 775 | case 5: |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 776 | c->code_rate_LP = FEC_NONE; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 777 | break; |
| 778 | } |
| 779 | |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 780 | return 0; |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 781 | |
Antti Palosaari | de7f14fc | 2012-04-05 21:14:32 -0300 | [diff] [blame] | 782 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 783 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 784 | |
| 785 | return ret; |
| 786 | } |
| 787 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 788 | static int af9033_read_status(struct dvb_frontend *fe, fe_status_t *status) |
| 789 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 790 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 791 | int ret; |
| 792 | u8 tmp; |
| 793 | |
| 794 | *status = 0; |
| 795 | |
| 796 | /* radio channel status, 0=no result, 1=has signal, 2=no signal */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 797 | ret = af9033_rd_reg(dev, 0x800047, &tmp); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 798 | if (ret < 0) |
| 799 | goto err; |
| 800 | |
| 801 | /* has signal */ |
| 802 | if (tmp == 0x01) |
| 803 | *status |= FE_HAS_SIGNAL; |
| 804 | |
| 805 | if (tmp != 0x02) { |
| 806 | /* TPS lock */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 807 | ret = af9033_rd_reg_mask(dev, 0x80f5a9, &tmp, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 808 | if (ret < 0) |
| 809 | goto err; |
| 810 | |
| 811 | if (tmp) |
| 812 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 813 | FE_HAS_VITERBI; |
| 814 | |
| 815 | /* full lock */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 816 | ret = af9033_rd_reg_mask(dev, 0x80f999, &tmp, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 817 | if (ret < 0) |
| 818 | goto err; |
| 819 | |
| 820 | if (tmp) |
| 821 | *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | |
| 822 | FE_HAS_VITERBI | FE_HAS_SYNC | |
| 823 | FE_HAS_LOCK; |
| 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | |
| 828 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 829 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 830 | |
| 831 | return ret; |
| 832 | } |
| 833 | |
| 834 | static int af9033_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 835 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 836 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 837 | int ret, i, len; |
| 838 | u8 buf[3], tmp; |
| 839 | u32 snr_val; |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 840 | const struct val_snr *snr_lut; |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 841 | |
| 842 | /* read value */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 843 | ret = af9033_rd_regs(dev, 0x80002c, buf, 3); |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 844 | if (ret < 0) |
| 845 | goto err; |
| 846 | |
| 847 | snr_val = (buf[2] << 16) | (buf[1] << 8) | buf[0]; |
| 848 | |
| 849 | /* read current modulation */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 850 | ret = af9033_rd_reg(dev, 0x80f903, &tmp); |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 851 | if (ret < 0) |
| 852 | goto err; |
| 853 | |
| 854 | switch ((tmp >> 0) & 3) { |
| 855 | case 0: |
| 856 | len = ARRAY_SIZE(qpsk_snr_lut); |
| 857 | snr_lut = qpsk_snr_lut; |
| 858 | break; |
| 859 | case 1: |
| 860 | len = ARRAY_SIZE(qam16_snr_lut); |
| 861 | snr_lut = qam16_snr_lut; |
| 862 | break; |
| 863 | case 2: |
| 864 | len = ARRAY_SIZE(qam64_snr_lut); |
| 865 | snr_lut = qam64_snr_lut; |
| 866 | break; |
| 867 | default: |
| 868 | goto err; |
| 869 | } |
| 870 | |
| 871 | for (i = 0; i < len; i++) { |
| 872 | tmp = snr_lut[i].snr; |
| 873 | |
| 874 | if (snr_val < snr_lut[i].val) |
| 875 | break; |
| 876 | } |
| 877 | |
| 878 | *snr = tmp * 10; /* dB/10 */ |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 879 | |
| 880 | return 0; |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 881 | |
| 882 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 883 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | e898ef6 | 2012-04-01 12:50:02 -0300 | [diff] [blame] | 884 | |
| 885 | return ret; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | static int af9033_read_signal_strength(struct dvb_frontend *fe, u16 *strength) |
| 889 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 890 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 891 | int ret; |
| 892 | u8 strength2; |
| 893 | |
| 894 | /* read signal strength of 0-100 scale */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 895 | ret = af9033_rd_reg(dev, 0x800048, &strength2); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 896 | if (ret < 0) |
| 897 | goto err; |
| 898 | |
| 899 | /* scale value to 0x0000-0xffff */ |
| 900 | *strength = strength2 * 0xffff / 100; |
| 901 | |
| 902 | return 0; |
| 903 | |
| 904 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 905 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 906 | |
| 907 | return ret; |
| 908 | } |
| 909 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 910 | static int af9033_update_ch_stat(struct af9033_dev *dev) |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 911 | { |
| 912 | int ret = 0; |
| 913 | u32 err_cnt, bit_cnt; |
| 914 | u16 abort_cnt; |
| 915 | u8 buf[7]; |
| 916 | |
| 917 | /* only update data every half second */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 918 | if (time_after(jiffies, dev->last_stat_check + msecs_to_jiffies(500))) { |
| 919 | ret = af9033_rd_regs(dev, 0x800032, buf, sizeof(buf)); |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 920 | if (ret < 0) |
| 921 | goto err; |
| 922 | /* in 8 byte packets? */ |
| 923 | abort_cnt = (buf[1] << 8) + buf[0]; |
| 924 | /* in bits */ |
| 925 | err_cnt = (buf[4] << 16) + (buf[3] << 8) + buf[2]; |
| 926 | /* in 8 byte packets? always(?) 0x2710 = 10000 */ |
| 927 | bit_cnt = (buf[6] << 8) + buf[5]; |
| 928 | |
| 929 | if (bit_cnt < abort_cnt) { |
| 930 | abort_cnt = 1000; |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 931 | dev->ber = 0xffffffff; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 932 | } else { |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 933 | /* |
| 934 | * 8 byte packets, that have not been rejected already |
| 935 | */ |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 936 | bit_cnt -= (u32)abort_cnt; |
| 937 | if (bit_cnt == 0) { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 938 | dev->ber = 0xffffffff; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 939 | } else { |
| 940 | err_cnt -= (u32)abort_cnt * 8 * 8; |
| 941 | bit_cnt *= 8 * 8; |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 942 | dev->ber = err_cnt * (0xffffffff / bit_cnt); |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 943 | } |
| 944 | } |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 945 | dev->ucb += abort_cnt; |
| 946 | dev->last_stat_check = jiffies; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | return 0; |
| 950 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 951 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 952 | |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 953 | return ret; |
| 954 | } |
| 955 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 956 | static int af9033_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 957 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 958 | struct af9033_dev *dev = fe->demodulator_priv; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 959 | int ret; |
| 960 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 961 | ret = af9033_update_ch_stat(dev); |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 962 | if (ret < 0) |
| 963 | return ret; |
| 964 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 965 | *ber = dev->ber; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 966 | |
| 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int af9033_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 971 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 972 | struct af9033_dev *dev = fe->demodulator_priv; |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 973 | int ret; |
| 974 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 975 | ret = af9033_update_ch_stat(dev); |
Hans-Frieder Vogt | 47eafa5 | 2012-04-07 10:34:34 -0300 | [diff] [blame] | 976 | if (ret < 0) |
| 977 | return ret; |
| 978 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 979 | *ucblocks = dev->ucb; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 980 | |
| 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | static int af9033_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 985 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 986 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 987 | int ret; |
| 988 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 989 | dev_dbg(&dev->i2c->dev, "%s: enable=%d\n", __func__, enable); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 990 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 991 | ret = af9033_wr_reg_mask(dev, 0x00fa04, enable, 0x01); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 992 | if (ret < 0) |
| 993 | goto err; |
| 994 | |
| 995 | return 0; |
| 996 | |
| 997 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 998 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 999 | |
| 1000 | return ret; |
| 1001 | } |
| 1002 | |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 1003 | static int af9033_pid_filter_ctrl(struct dvb_frontend *fe, int onoff) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1004 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1005 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1006 | int ret; |
| 1007 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1008 | dev_dbg(&dev->i2c->dev, "%s: onoff=%d\n", __func__, onoff); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1009 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1010 | ret = af9033_wr_reg_mask(dev, 0x80f993, onoff, 0x01); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1011 | if (ret < 0) |
| 1012 | goto err; |
| 1013 | |
| 1014 | return 0; |
| 1015 | |
| 1016 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1017 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1018 | |
| 1019 | return ret; |
| 1020 | } |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1021 | |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 1022 | static int af9033_pid_filter(struct dvb_frontend *fe, int index, u16 pid, |
| 1023 | int onoff) |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1024 | { |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1025 | struct af9033_dev *dev = fe->demodulator_priv; |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1026 | int ret; |
| 1027 | u8 wbuf[2] = {(pid >> 0) & 0xff, (pid >> 8) & 0xff}; |
| 1028 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1029 | dev_dbg(&dev->i2c->dev, "%s: index=%d pid=%04x onoff=%d\n", |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1030 | __func__, index, pid, onoff); |
| 1031 | |
| 1032 | if (pid > 0x1fff) |
| 1033 | return 0; |
| 1034 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1035 | ret = af9033_wr_regs(dev, 0x80f996, wbuf, 2); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1036 | if (ret < 0) |
| 1037 | goto err; |
| 1038 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1039 | ret = af9033_wr_reg(dev, 0x80f994, onoff); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1040 | if (ret < 0) |
| 1041 | goto err; |
| 1042 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1043 | ret = af9033_wr_reg(dev, 0x80f995, index); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1044 | if (ret < 0) |
| 1045 | goto err; |
| 1046 | |
| 1047 | return 0; |
| 1048 | |
| 1049 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1050 | dev_dbg(&dev->i2c->dev, "%s: failed=%d\n", __func__, ret); |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1051 | |
| 1052 | return ret; |
| 1053 | } |
Antti Palosaari | 040cf86 | 2014-02-13 15:40:59 -0300 | [diff] [blame] | 1054 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1055 | static struct dvb_frontend_ops af9033_ops; |
| 1056 | |
| 1057 | struct dvb_frontend *af9033_attach(const struct af9033_config *config, |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 1058 | struct i2c_adapter *i2c, |
| 1059 | struct af9033_ops *ops) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1060 | { |
| 1061 | int ret; |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1062 | struct af9033_dev *dev; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1063 | u8 buf[8]; |
Antti Palosaari | ef5211f | 2014-08-31 02:03:05 -0300 | [diff] [blame] | 1064 | u32 reg; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1065 | |
Antti Palosaari | 0a73f2d | 2012-09-12 20:23:42 -0300 | [diff] [blame] | 1066 | dev_dbg(&i2c->dev, "%s:\n", __func__); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1067 | |
| 1068 | /* allocate memory for the internal state */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1069 | dev = kzalloc(sizeof(struct af9033_dev), GFP_KERNEL); |
| 1070 | if (dev == NULL) |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1071 | goto err; |
| 1072 | |
| 1073 | /* setup the state */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1074 | dev->i2c = i2c; |
| 1075 | memcpy(&dev->cfg, config, sizeof(struct af9033_config)); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1076 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1077 | if (dev->cfg.clock != 12000000) { |
| 1078 | dev_err(&dev->i2c->dev, |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 1079 | "%s: af9033: unsupported clock=%d, only 12000000 Hz is supported currently\n", |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1080 | KBUILD_MODNAME, dev->cfg.clock); |
Antti Palosaari | 8e8a5ac | 2012-04-01 14:13:36 -0300 | [diff] [blame] | 1081 | goto err; |
| 1082 | } |
| 1083 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1084 | /* firmware version */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1085 | switch (dev->cfg.tuner) { |
Antti Palosaari | ef5211f | 2014-08-31 02:03:05 -0300 | [diff] [blame] | 1086 | case AF9033_TUNER_IT9135_38: |
| 1087 | case AF9033_TUNER_IT9135_51: |
| 1088 | case AF9033_TUNER_IT9135_52: |
| 1089 | case AF9033_TUNER_IT9135_60: |
| 1090 | case AF9033_TUNER_IT9135_61: |
| 1091 | case AF9033_TUNER_IT9135_62: |
| 1092 | reg = 0x004bfc; |
| 1093 | break; |
| 1094 | default: |
| 1095 | reg = 0x0083e9; |
| 1096 | break; |
| 1097 | } |
| 1098 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1099 | ret = af9033_rd_regs(dev, reg, &buf[0], 4); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1100 | if (ret < 0) |
| 1101 | goto err; |
| 1102 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1103 | ret = af9033_rd_regs(dev, 0x804191, &buf[4], 4); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1104 | if (ret < 0) |
| 1105 | goto err; |
| 1106 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1107 | dev_info(&dev->i2c->dev, |
Antti Palosaari | 24e419a | 2014-08-09 14:59:53 -0300 | [diff] [blame] | 1108 | "%s: firmware version: LINK=%d.%d.%d.%d OFDM=%d.%d.%d.%d\n", |
| 1109 | KBUILD_MODNAME, buf[0], buf[1], buf[2], buf[3], buf[4], |
| 1110 | buf[5], buf[6], buf[7]); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1111 | |
Antti Palosaari | 0c13c54 | 2013-03-07 23:13:31 -0300 | [diff] [blame] | 1112 | /* sleep */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1113 | switch (dev->cfg.tuner) { |
Antti Palosaari | 0c13c54 | 2013-03-07 23:13:31 -0300 | [diff] [blame] | 1114 | case AF9033_TUNER_IT9135_38: |
| 1115 | case AF9033_TUNER_IT9135_51: |
| 1116 | case AF9033_TUNER_IT9135_52: |
| 1117 | case AF9033_TUNER_IT9135_60: |
| 1118 | case AF9033_TUNER_IT9135_61: |
| 1119 | case AF9033_TUNER_IT9135_62: |
| 1120 | /* IT9135 did not like to sleep at that early */ |
| 1121 | break; |
| 1122 | default: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1123 | ret = af9033_wr_reg(dev, 0x80004c, 1); |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 1124 | if (ret < 0) |
| 1125 | goto err; |
| 1126 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1127 | ret = af9033_wr_reg(dev, 0x800000, 0); |
Antti Palosaari | 4902bb3 | 2013-01-07 09:48:03 -0300 | [diff] [blame] | 1128 | if (ret < 0) |
| 1129 | goto err; |
| 1130 | } |
Antti Palosaari | 12897dc | 2012-09-16 22:26:57 -0300 | [diff] [blame] | 1131 | |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1132 | /* configure internal TS mode */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1133 | switch (dev->cfg.ts_mode) { |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1134 | case AF9033_TS_MODE_PARALLEL: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1135 | dev->ts_mode_parallel = true; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1136 | break; |
| 1137 | case AF9033_TS_MODE_SERIAL: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1138 | dev->ts_mode_serial = true; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1139 | break; |
| 1140 | case AF9033_TS_MODE_USB: |
| 1141 | /* usb mode for AF9035 */ |
| 1142 | default: |
| 1143 | break; |
| 1144 | } |
| 1145 | |
| 1146 | /* create dvb_frontend */ |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1147 | memcpy(&dev->fe.ops, &af9033_ops, sizeof(struct dvb_frontend_ops)); |
| 1148 | dev->fe.demodulator_priv = dev; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1149 | |
Mauro Carvalho Chehab | ed97a6f | 2014-03-14 14:29:06 -0300 | [diff] [blame] | 1150 | if (ops) { |
| 1151 | ops->pid_filter = af9033_pid_filter; |
| 1152 | ops->pid_filter_ctrl = af9033_pid_filter_ctrl; |
| 1153 | } |
| 1154 | |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1155 | return &dev->fe; |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1156 | |
| 1157 | err: |
Antti Palosaari | 09611ca | 2014-08-31 02:18:34 -0300 | [diff] [blame^] | 1158 | kfree(dev); |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1159 | return NULL; |
| 1160 | } |
| 1161 | EXPORT_SYMBOL(af9033_attach); |
| 1162 | |
| 1163 | static struct dvb_frontend_ops af9033_ops = { |
| 1164 | .delsys = { SYS_DVBT }, |
| 1165 | .info = { |
| 1166 | .name = "Afatech AF9033 (DVB-T)", |
| 1167 | .frequency_min = 174000000, |
| 1168 | .frequency_max = 862000000, |
| 1169 | .frequency_stepsize = 250000, |
| 1170 | .frequency_tolerance = 0, |
| 1171 | .caps = FE_CAN_FEC_1_2 | |
| 1172 | FE_CAN_FEC_2_3 | |
| 1173 | FE_CAN_FEC_3_4 | |
| 1174 | FE_CAN_FEC_5_6 | |
| 1175 | FE_CAN_FEC_7_8 | |
| 1176 | FE_CAN_FEC_AUTO | |
| 1177 | FE_CAN_QPSK | |
| 1178 | FE_CAN_QAM_16 | |
| 1179 | FE_CAN_QAM_64 | |
| 1180 | FE_CAN_QAM_AUTO | |
| 1181 | FE_CAN_TRANSMISSION_MODE_AUTO | |
| 1182 | FE_CAN_GUARD_INTERVAL_AUTO | |
| 1183 | FE_CAN_HIERARCHY_AUTO | |
| 1184 | FE_CAN_RECOVER | |
| 1185 | FE_CAN_MUTE_TS |
| 1186 | }, |
| 1187 | |
| 1188 | .release = af9033_release, |
| 1189 | |
| 1190 | .init = af9033_init, |
| 1191 | .sleep = af9033_sleep, |
| 1192 | |
| 1193 | .get_tune_settings = af9033_get_tune_settings, |
| 1194 | .set_frontend = af9033_set_frontend, |
Gianluca Gennari | 0a4df23 | 2012-04-05 12:47:19 -0300 | [diff] [blame] | 1195 | .get_frontend = af9033_get_frontend, |
Antti Palosaari | 4b64bb2 | 2012-03-30 08:21:25 -0300 | [diff] [blame] | 1196 | |
| 1197 | .read_status = af9033_read_status, |
| 1198 | .read_snr = af9033_read_snr, |
| 1199 | .read_signal_strength = af9033_read_signal_strength, |
| 1200 | .read_ber = af9033_read_ber, |
| 1201 | .read_ucblocks = af9033_read_ucblocks, |
| 1202 | |
| 1203 | .i2c_gate_ctrl = af9033_i2c_gate_ctrl, |
| 1204 | }; |
| 1205 | |
| 1206 | MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); |
| 1207 | MODULE_DESCRIPTION("Afatech AF9033 DVB-T demodulator driver"); |
| 1208 | MODULE_LICENSE("GPL"); |