Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Support for LGDT3306A - 8VSB/QAM-B |
| 3 | * |
| 4 | * Copyright (C) 2013 Fred Richter <frichter@hauppauge.com> |
| 5 | * - driver structure based on lgdt3305.[ch] by Michael Krufky |
| 6 | * - code based on LG3306_V0.35 API by LG Electronics Inc. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 17 | */ |
| 18 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 19 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 20 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 21 | #include <asm/div64.h> |
| 22 | #include <linux/dvb/frontend.h> |
| 23 | #include "dvb_math.h" |
| 24 | #include "lgdt3306a.h" |
| 25 | |
| 26 | |
| 27 | static int debug; |
| 28 | module_param(debug, int, 0644); |
| 29 | MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))"); |
| 30 | |
| 31 | #define DBG_INFO 1 |
| 32 | #define DBG_REG 2 |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 33 | #define DBG_DUMP 4 /* FGR - comment out to remove dump code */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 34 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 35 | #define lg_debug(fmt, arg...) \ |
| 36 | printk(KERN_DEBUG pr_fmt(fmt), ## arg) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 37 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 38 | #define dbg_info(fmt, arg...) \ |
| 39 | do { \ |
| 40 | if (debug & DBG_INFO) \ |
| 41 | lg_debug(fmt, ## arg); \ |
| 42 | } while (0) |
| 43 | |
| 44 | #define dbg_reg(fmt, arg...) \ |
| 45 | do { \ |
| 46 | if (debug & DBG_REG) \ |
| 47 | lg_debug(fmt, ## arg); \ |
| 48 | } while (0) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 49 | |
| 50 | #define lg_chkerr(ret) \ |
| 51 | ({ \ |
| 52 | int __ret; \ |
| 53 | __ret = (ret < 0); \ |
| 54 | if (__ret) \ |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 55 | pr_err("error %d on line %d\n", ret, __LINE__); \ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 56 | __ret; \ |
| 57 | }) |
| 58 | |
| 59 | struct lgdt3306a_state { |
| 60 | struct i2c_adapter *i2c_adap; |
| 61 | const struct lgdt3306a_config *cfg; |
| 62 | |
| 63 | struct dvb_frontend frontend; |
| 64 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 65 | enum fe_modulation current_modulation; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 66 | u32 current_frequency; |
| 67 | u32 snr; |
| 68 | }; |
| 69 | |
Mauro Carvalho Chehab | 95f22c5 | 2014-10-28 12:40:20 -0200 | [diff] [blame] | 70 | /* |
| 71 | * LG3306A Register Usage |
| 72 | * (LG does not really name the registers, so this code does not either) |
| 73 | * |
| 74 | * 0000 -> 00FF Common control and status |
| 75 | * 1000 -> 10FF Synchronizer control and status |
| 76 | * 1F00 -> 1FFF Smart Antenna control and status |
| 77 | * 2100 -> 21FF VSB Equalizer control and status |
| 78 | * 2800 -> 28FF QAM Equalizer control and status |
| 79 | * 3000 -> 30FF FEC control and status |
| 80 | */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 81 | |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 82 | enum lgdt3306a_lock_status { |
| 83 | LG3306_UNLOCK = 0x00, |
| 84 | LG3306_LOCK = 0x01, |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 85 | LG3306_UNKNOWN_LOCK = 0xff |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 86 | }; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 87 | |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 88 | enum lgdt3306a_neverlock_status { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 89 | LG3306_NL_INIT = 0x00, |
| 90 | LG3306_NL_PROCESS = 0x01, |
| 91 | LG3306_NL_LOCK = 0x02, |
| 92 | LG3306_NL_FAIL = 0x03, |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 93 | LG3306_NL_UNKNOWN = 0xff |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 94 | }; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 95 | |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 96 | enum lgdt3306a_modulation { |
| 97 | LG3306_VSB = 0x00, |
| 98 | LG3306_QAM64 = 0x01, |
| 99 | LG3306_QAM256 = 0x02, |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 100 | LG3306_UNKNOWN_MODE = 0xff |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 101 | }; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 102 | |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 103 | enum lgdt3306a_lock_check { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 104 | LG3306_SYNC_LOCK, |
| 105 | LG3306_FEC_LOCK, |
| 106 | LG3306_TR_LOCK, |
| 107 | LG3306_AGC_LOCK, |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 108 | }; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 109 | |
| 110 | |
| 111 | #ifdef DBG_DUMP |
| 112 | static void lgdt3306a_DumpAllRegs(struct lgdt3306a_state *state); |
| 113 | static void lgdt3306a_DumpRegs(struct lgdt3306a_state *state); |
| 114 | #endif |
| 115 | |
| 116 | |
| 117 | static int lgdt3306a_write_reg(struct lgdt3306a_state *state, u16 reg, u8 val) |
| 118 | { |
| 119 | int ret; |
| 120 | u8 buf[] = { reg >> 8, reg & 0xff, val }; |
| 121 | struct i2c_msg msg = { |
| 122 | .addr = state->cfg->i2c_addr, .flags = 0, |
| 123 | .buf = buf, .len = 3, |
| 124 | }; |
| 125 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 126 | dbg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 127 | |
| 128 | ret = i2c_transfer(state->i2c_adap, &msg, 1); |
| 129 | |
| 130 | if (ret != 1) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 131 | pr_err("error (addr %02x %02x <- %02x, err = %i)\n", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 132 | msg.buf[0], msg.buf[1], msg.buf[2], ret); |
| 133 | if (ret < 0) |
| 134 | return ret; |
| 135 | else |
| 136 | return -EREMOTEIO; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static int lgdt3306a_read_reg(struct lgdt3306a_state *state, u16 reg, u8 *val) |
| 142 | { |
| 143 | int ret; |
| 144 | u8 reg_buf[] = { reg >> 8, reg & 0xff }; |
| 145 | struct i2c_msg msg[] = { |
| 146 | { .addr = state->cfg->i2c_addr, |
| 147 | .flags = 0, .buf = reg_buf, .len = 2 }, |
| 148 | { .addr = state->cfg->i2c_addr, |
| 149 | .flags = I2C_M_RD, .buf = val, .len = 1 }, |
| 150 | }; |
| 151 | |
| 152 | ret = i2c_transfer(state->i2c_adap, msg, 2); |
| 153 | |
| 154 | if (ret != 2) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 155 | pr_err("error (addr %02x reg %04x error (ret == %i)\n", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 156 | state->cfg->i2c_addr, reg, ret); |
| 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | else |
| 160 | return -EREMOTEIO; |
| 161 | } |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 162 | dbg_reg("reg: 0x%04x, val: 0x%02x\n", reg, *val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | #define read_reg(state, reg) \ |
| 168 | ({ \ |
| 169 | u8 __val; \ |
| 170 | int ret = lgdt3306a_read_reg(state, reg, &__val); \ |
| 171 | if (lg_chkerr(ret)) \ |
| 172 | __val = 0; \ |
| 173 | __val; \ |
| 174 | }) |
| 175 | |
| 176 | static int lgdt3306a_set_reg_bit(struct lgdt3306a_state *state, |
| 177 | u16 reg, int bit, int onoff) |
| 178 | { |
| 179 | u8 val; |
| 180 | int ret; |
| 181 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 182 | dbg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 183 | |
| 184 | ret = lgdt3306a_read_reg(state, reg, &val); |
| 185 | if (lg_chkerr(ret)) |
| 186 | goto fail; |
| 187 | |
| 188 | val &= ~(1 << bit); |
| 189 | val |= (onoff & 1) << bit; |
| 190 | |
| 191 | ret = lgdt3306a_write_reg(state, reg, val); |
| 192 | lg_chkerr(ret); |
| 193 | fail: |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | /* ------------------------------------------------------------------------ */ |
| 198 | |
| 199 | static int lgdt3306a_soft_reset(struct lgdt3306a_state *state) |
| 200 | { |
| 201 | int ret; |
| 202 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 203 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 204 | |
| 205 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 0); |
| 206 | if (lg_chkerr(ret)) |
| 207 | goto fail; |
| 208 | |
| 209 | msleep(20); |
| 210 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 1); |
| 211 | lg_chkerr(ret); |
| 212 | |
| 213 | fail: |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | static int lgdt3306a_mpeg_mode(struct lgdt3306a_state *state, |
| 218 | enum lgdt3306a_mpeg_mode mode) |
| 219 | { |
| 220 | u8 val; |
| 221 | int ret; |
| 222 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 223 | dbg_info("(%d)\n", mode); |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 224 | /* transport packet format - TPSENB=0x80 */ |
| 225 | ret = lgdt3306a_set_reg_bit(state, 0x0071, 7, |
| 226 | mode == LGDT3306A_MPEG_PARALLEL ? 1 : 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 227 | if (lg_chkerr(ret)) |
| 228 | goto fail; |
| 229 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 230 | /* |
| 231 | * start of packet signal duration |
| 232 | * TPSSOPBITEN=0x40; 0=byte duration, 1=bit duration |
| 233 | */ |
| 234 | ret = lgdt3306a_set_reg_bit(state, 0x0071, 6, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 235 | if (lg_chkerr(ret)) |
| 236 | goto fail; |
| 237 | |
| 238 | ret = lgdt3306a_read_reg(state, 0x0070, &val); |
| 239 | if (lg_chkerr(ret)) |
| 240 | goto fail; |
| 241 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 242 | val |= 0x10; /* TPCLKSUPB=0x10 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 243 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 244 | if (mode == LGDT3306A_MPEG_PARALLEL) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 245 | val &= ~0x10; |
| 246 | |
| 247 | ret = lgdt3306a_write_reg(state, 0x0070, val); |
| 248 | lg_chkerr(ret); |
| 249 | |
| 250 | fail: |
| 251 | return ret; |
| 252 | } |
| 253 | |
| 254 | static int lgdt3306a_mpeg_mode_polarity(struct lgdt3306a_state *state, |
| 255 | enum lgdt3306a_tp_clock_edge edge, |
| 256 | enum lgdt3306a_tp_valid_polarity valid) |
| 257 | { |
| 258 | u8 val; |
| 259 | int ret; |
| 260 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 261 | dbg_info("edge=%d, valid=%d\n", edge, valid); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 262 | |
| 263 | ret = lgdt3306a_read_reg(state, 0x0070, &val); |
| 264 | if (lg_chkerr(ret)) |
| 265 | goto fail; |
| 266 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 267 | val &= ~0x06; /* TPCLKPOL=0x04, TPVALPOL=0x02 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 268 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 269 | if (edge == LGDT3306A_TPCLK_RISING_EDGE) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 270 | val |= 0x04; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 271 | if (valid == LGDT3306A_TP_VALID_HIGH) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 272 | val |= 0x02; |
| 273 | |
| 274 | ret = lgdt3306a_write_reg(state, 0x0070, val); |
| 275 | lg_chkerr(ret); |
| 276 | |
| 277 | fail: |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | static int lgdt3306a_mpeg_tristate(struct lgdt3306a_state *state, |
| 282 | int mode) |
| 283 | { |
| 284 | u8 val; |
| 285 | int ret; |
| 286 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 287 | dbg_info("(%d)\n", mode); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 288 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 289 | if (mode) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 290 | ret = lgdt3306a_read_reg(state, 0x0070, &val); |
| 291 | if (lg_chkerr(ret)) |
| 292 | goto fail; |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 293 | /* |
| 294 | * Tristate bus; TPOUTEN=0x80, TPCLKOUTEN=0x20, |
| 295 | * TPDATAOUTEN=0x08 |
| 296 | */ |
| 297 | val &= ~0xa8; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 298 | ret = lgdt3306a_write_reg(state, 0x0070, val); |
| 299 | if (lg_chkerr(ret)) |
| 300 | goto fail; |
| 301 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 302 | /* AGCIFOUTENB=0x40; 1=Disable IFAGC pin */ |
| 303 | ret = lgdt3306a_set_reg_bit(state, 0x0003, 6, 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 304 | if (lg_chkerr(ret)) |
| 305 | goto fail; |
| 306 | |
| 307 | } else { |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 308 | /* enable IFAGC pin */ |
| 309 | ret = lgdt3306a_set_reg_bit(state, 0x0003, 6, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 310 | if (lg_chkerr(ret)) |
| 311 | goto fail; |
| 312 | |
| 313 | ret = lgdt3306a_read_reg(state, 0x0070, &val); |
| 314 | if (lg_chkerr(ret)) |
| 315 | goto fail; |
| 316 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 317 | val |= 0xa8; /* enable bus */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 318 | ret = lgdt3306a_write_reg(state, 0x0070, val); |
| 319 | if (lg_chkerr(ret)) |
| 320 | goto fail; |
| 321 | } |
| 322 | |
| 323 | fail: |
| 324 | return ret; |
| 325 | } |
| 326 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 327 | static int lgdt3306a_ts_bus_ctrl(struct dvb_frontend *fe, int acquire) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 328 | { |
| 329 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 330 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 331 | dbg_info("acquire=%d\n", acquire); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 332 | |
| 333 | return lgdt3306a_mpeg_tristate(state, acquire ? 0 : 1); |
| 334 | |
| 335 | } |
| 336 | |
| 337 | static int lgdt3306a_power(struct lgdt3306a_state *state, |
| 338 | int mode) |
| 339 | { |
| 340 | int ret; |
| 341 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 342 | dbg_info("(%d)\n", mode); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 343 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 344 | if (mode == 0) { |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 345 | /* into reset */ |
| 346 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 347 | if (lg_chkerr(ret)) |
| 348 | goto fail; |
| 349 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 350 | /* power down */ |
| 351 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 0, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 352 | if (lg_chkerr(ret)) |
| 353 | goto fail; |
| 354 | |
| 355 | } else { |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 356 | /* out of reset */ |
| 357 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 358 | if (lg_chkerr(ret)) |
| 359 | goto fail; |
| 360 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 361 | /* power up */ |
| 362 | ret = lgdt3306a_set_reg_bit(state, 0x0000, 0, 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 363 | if (lg_chkerr(ret)) |
| 364 | goto fail; |
| 365 | } |
| 366 | |
| 367 | #ifdef DBG_DUMP |
| 368 | lgdt3306a_DumpAllRegs(state); |
| 369 | #endif |
| 370 | fail: |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | |
| 375 | static int lgdt3306a_set_vsb(struct lgdt3306a_state *state) |
| 376 | { |
| 377 | u8 val; |
| 378 | int ret; |
| 379 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 380 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 381 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 382 | /* 0. Spectrum inversion detection manual; spectrum inverted */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 383 | ret = lgdt3306a_read_reg(state, 0x0002, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 384 | val &= 0xf7; /* SPECINVAUTO Off */ |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 385 | val |= 0x04; /* SPECINV On */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 386 | ret = lgdt3306a_write_reg(state, 0x0002, val); |
| 387 | if (lg_chkerr(ret)) |
| 388 | goto fail; |
| 389 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 390 | /* 1. Selection of standard mode(0x08=QAM, 0x80=VSB) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 391 | ret = lgdt3306a_write_reg(state, 0x0008, 0x80); |
| 392 | if (lg_chkerr(ret)) |
| 393 | goto fail; |
| 394 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 395 | /* 2. Bandwidth mode for VSB(6MHz) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 396 | ret = lgdt3306a_read_reg(state, 0x0009, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 397 | val &= 0xe3; |
| 398 | val |= 0x0c; /* STDOPDETTMODE[2:0]=3 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 399 | ret = lgdt3306a_write_reg(state, 0x0009, val); |
| 400 | if (lg_chkerr(ret)) |
| 401 | goto fail; |
| 402 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 403 | /* 3. QAM mode detection mode(None) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 404 | ret = lgdt3306a_read_reg(state, 0x0009, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 405 | val &= 0xfc; /* STDOPDETCMODE[1:0]=0 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 406 | ret = lgdt3306a_write_reg(state, 0x0009, val); |
| 407 | if (lg_chkerr(ret)) |
| 408 | goto fail; |
| 409 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 410 | /* 4. ADC sampling frequency rate(2x sampling) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 411 | ret = lgdt3306a_read_reg(state, 0x000d, &val); |
| 412 | val &= 0xbf; /* SAMPLING4XFEN=0 */ |
| 413 | ret = lgdt3306a_write_reg(state, 0x000d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 414 | if (lg_chkerr(ret)) |
| 415 | goto fail; |
| 416 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 417 | #if 0 |
| 418 | /* FGR - disable any AICC filtering, testing only */ |
| 419 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 420 | ret = lgdt3306a_write_reg(state, 0x0024, 0x00); |
| 421 | if (lg_chkerr(ret)) |
| 422 | goto fail; |
| 423 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 424 | /* AICCFIXFREQ0 NT N-1(Video rejection) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 425 | ret = lgdt3306a_write_reg(state, 0x002e, 0x00); |
| 426 | ret = lgdt3306a_write_reg(state, 0x002f, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 427 | ret = lgdt3306a_write_reg(state, 0x0030, 0x00); |
| 428 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 429 | /* AICCFIXFREQ1 NT N-1(Audio rejection) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 430 | ret = lgdt3306a_write_reg(state, 0x002b, 0x00); |
| 431 | ret = lgdt3306a_write_reg(state, 0x002c, 0x00); |
| 432 | ret = lgdt3306a_write_reg(state, 0x002d, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 433 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 434 | /* AICCFIXFREQ2 NT Co-Channel(Video rejection) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 435 | ret = lgdt3306a_write_reg(state, 0x0028, 0x00); |
| 436 | ret = lgdt3306a_write_reg(state, 0x0029, 0x00); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 437 | ret = lgdt3306a_write_reg(state, 0x002a, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 438 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 439 | /* AICCFIXFREQ3 NT Co-Channel(Audio rejection) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 440 | ret = lgdt3306a_write_reg(state, 0x0025, 0x00); |
| 441 | ret = lgdt3306a_write_reg(state, 0x0026, 0x00); |
| 442 | ret = lgdt3306a_write_reg(state, 0x0027, 0x00); |
| 443 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 444 | #else |
| 445 | /* FGR - this works well for HVR-1955,1975 */ |
| 446 | |
| 447 | /* 5. AICCOPMODE NT N-1 Adj. */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 448 | ret = lgdt3306a_write_reg(state, 0x0024, 0x5A); |
| 449 | if (lg_chkerr(ret)) |
| 450 | goto fail; |
| 451 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 452 | /* AICCFIXFREQ0 NT N-1(Video rejection) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 453 | ret = lgdt3306a_write_reg(state, 0x002e, 0x5A); |
| 454 | ret = lgdt3306a_write_reg(state, 0x002f, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 455 | ret = lgdt3306a_write_reg(state, 0x0030, 0x00); |
| 456 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 457 | /* AICCFIXFREQ1 NT N-1(Audio rejection) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 458 | ret = lgdt3306a_write_reg(state, 0x002b, 0x36); |
| 459 | ret = lgdt3306a_write_reg(state, 0x002c, 0x00); |
| 460 | ret = lgdt3306a_write_reg(state, 0x002d, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 461 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 462 | /* AICCFIXFREQ2 NT Co-Channel(Video rejection) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 463 | ret = lgdt3306a_write_reg(state, 0x0028, 0x2A); |
| 464 | ret = lgdt3306a_write_reg(state, 0x0029, 0x00); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 465 | ret = lgdt3306a_write_reg(state, 0x002a, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 466 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 467 | /* AICCFIXFREQ3 NT Co-Channel(Audio rejection) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 468 | ret = lgdt3306a_write_reg(state, 0x0025, 0x06); |
| 469 | ret = lgdt3306a_write_reg(state, 0x0026, 0x00); |
| 470 | ret = lgdt3306a_write_reg(state, 0x0027, 0x00); |
| 471 | #endif |
| 472 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 473 | ret = lgdt3306a_read_reg(state, 0x001e, &val); |
| 474 | val &= 0x0f; |
| 475 | val |= 0xa0; |
| 476 | ret = lgdt3306a_write_reg(state, 0x001e, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 477 | |
| 478 | ret = lgdt3306a_write_reg(state, 0x0022, 0x08); |
| 479 | |
| 480 | ret = lgdt3306a_write_reg(state, 0x0023, 0xFF); |
| 481 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 482 | ret = lgdt3306a_read_reg(state, 0x211f, &val); |
| 483 | val &= 0xef; |
| 484 | ret = lgdt3306a_write_reg(state, 0x211f, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 485 | |
| 486 | ret = lgdt3306a_write_reg(state, 0x2173, 0x01); |
| 487 | |
| 488 | ret = lgdt3306a_read_reg(state, 0x1061, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 489 | val &= 0xf8; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 490 | val |= 0x04; |
| 491 | ret = lgdt3306a_write_reg(state, 0x1061, val); |
| 492 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 493 | ret = lgdt3306a_read_reg(state, 0x103d, &val); |
| 494 | val &= 0xcf; |
| 495 | ret = lgdt3306a_write_reg(state, 0x103d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 496 | |
| 497 | ret = lgdt3306a_write_reg(state, 0x2122, 0x40); |
| 498 | |
| 499 | ret = lgdt3306a_read_reg(state, 0x2141, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 500 | val &= 0x3f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 501 | ret = lgdt3306a_write_reg(state, 0x2141, val); |
| 502 | |
| 503 | ret = lgdt3306a_read_reg(state, 0x2135, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 504 | val &= 0x0f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 505 | val |= 0x70; |
| 506 | ret = lgdt3306a_write_reg(state, 0x2135, val); |
| 507 | |
| 508 | ret = lgdt3306a_read_reg(state, 0x0003, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 509 | val &= 0xf7; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 510 | ret = lgdt3306a_write_reg(state, 0x0003, val); |
| 511 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 512 | ret = lgdt3306a_read_reg(state, 0x001c, &val); |
| 513 | val &= 0x7f; |
| 514 | ret = lgdt3306a_write_reg(state, 0x001c, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 515 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 516 | /* 6. EQ step size */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 517 | ret = lgdt3306a_read_reg(state, 0x2179, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 518 | val &= 0xf8; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 519 | ret = lgdt3306a_write_reg(state, 0x2179, val); |
| 520 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 521 | ret = lgdt3306a_read_reg(state, 0x217a, &val); |
| 522 | val &= 0xf8; |
| 523 | ret = lgdt3306a_write_reg(state, 0x217a, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 524 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 525 | /* 7. Reset */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 526 | ret = lgdt3306a_soft_reset(state); |
| 527 | if (lg_chkerr(ret)) |
| 528 | goto fail; |
| 529 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 530 | dbg_info("complete\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 531 | fail: |
| 532 | return ret; |
| 533 | } |
| 534 | |
| 535 | static int lgdt3306a_set_qam(struct lgdt3306a_state *state, int modulation) |
| 536 | { |
| 537 | u8 val; |
| 538 | int ret; |
| 539 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 540 | dbg_info("modulation=%d\n", modulation); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 541 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 542 | /* 1. Selection of standard mode(0x08=QAM, 0x80=VSB) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 543 | ret = lgdt3306a_write_reg(state, 0x0008, 0x08); |
| 544 | if (lg_chkerr(ret)) |
| 545 | goto fail; |
| 546 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 547 | /* 1a. Spectrum inversion detection to Auto */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 548 | ret = lgdt3306a_read_reg(state, 0x0002, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 549 | val &= 0xfb; /* SPECINV Off */ |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 550 | val |= 0x08; /* SPECINVAUTO On */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 551 | ret = lgdt3306a_write_reg(state, 0x0002, val); |
| 552 | if (lg_chkerr(ret)) |
| 553 | goto fail; |
| 554 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 555 | /* 2. Bandwidth mode for QAM */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 556 | ret = lgdt3306a_read_reg(state, 0x0009, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 557 | val &= 0xe3; /* STDOPDETTMODE[2:0]=0 VSB Off */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 558 | ret = lgdt3306a_write_reg(state, 0x0009, val); |
| 559 | if (lg_chkerr(ret)) |
| 560 | goto fail; |
| 561 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 562 | /* 3. : 64QAM/256QAM detection(manual, auto) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 563 | ret = lgdt3306a_read_reg(state, 0x0009, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 564 | val &= 0xfc; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 565 | val |= 0x02; /* STDOPDETCMODE[1:0]=1=Manual 2=Auto */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 566 | ret = lgdt3306a_write_reg(state, 0x0009, val); |
| 567 | if (lg_chkerr(ret)) |
| 568 | goto fail; |
| 569 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 570 | /* 3a. : 64QAM/256QAM selection for manual */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 571 | ret = lgdt3306a_read_reg(state, 0x101a, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 572 | val &= 0xf8; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 573 | if (modulation == QAM_64) |
| 574 | val |= 0x02; /* QMDQMODE[2:0]=2=QAM64 */ |
| 575 | else |
| 576 | val |= 0x04; /* QMDQMODE[2:0]=4=QAM256 */ |
| 577 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 578 | ret = lgdt3306a_write_reg(state, 0x101a, val); |
| 579 | if (lg_chkerr(ret)) |
| 580 | goto fail; |
| 581 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 582 | /* 4. ADC sampling frequency rate(4x sampling) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 583 | ret = lgdt3306a_read_reg(state, 0x000d, &val); |
| 584 | val &= 0xbf; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 585 | val |= 0x40; /* SAMPLING4XFEN=1 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 586 | ret = lgdt3306a_write_reg(state, 0x000d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 587 | if (lg_chkerr(ret)) |
| 588 | goto fail; |
| 589 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 590 | /* 5. No AICC operation in QAM mode */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 591 | ret = lgdt3306a_read_reg(state, 0x0024, &val); |
| 592 | val &= 0x00; |
| 593 | ret = lgdt3306a_write_reg(state, 0x0024, val); |
| 594 | if (lg_chkerr(ret)) |
| 595 | goto fail; |
| 596 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 597 | /* 6. Reset */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 598 | ret = lgdt3306a_soft_reset(state); |
| 599 | if (lg_chkerr(ret)) |
| 600 | goto fail; |
| 601 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 602 | dbg_info("complete\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 603 | fail: |
| 604 | return ret; |
| 605 | } |
| 606 | |
| 607 | static int lgdt3306a_set_modulation(struct lgdt3306a_state *state, |
| 608 | struct dtv_frontend_properties *p) |
| 609 | { |
| 610 | int ret; |
| 611 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 612 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 613 | |
| 614 | switch (p->modulation) { |
| 615 | case VSB_8: |
| 616 | ret = lgdt3306a_set_vsb(state); |
| 617 | break; |
| 618 | case QAM_64: |
| 619 | ret = lgdt3306a_set_qam(state, QAM_64); |
| 620 | break; |
| 621 | case QAM_256: |
| 622 | ret = lgdt3306a_set_qam(state, QAM_256); |
| 623 | break; |
| 624 | default: |
| 625 | return -EINVAL; |
| 626 | } |
| 627 | if (lg_chkerr(ret)) |
| 628 | goto fail; |
| 629 | |
| 630 | state->current_modulation = p->modulation; |
| 631 | |
| 632 | fail: |
| 633 | return ret; |
| 634 | } |
| 635 | |
| 636 | /* ------------------------------------------------------------------------ */ |
| 637 | |
| 638 | static int lgdt3306a_agc_setup(struct lgdt3306a_state *state, |
| 639 | struct dtv_frontend_properties *p) |
| 640 | { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 641 | /* TODO: anything we want to do here??? */ |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 642 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 643 | |
| 644 | switch (p->modulation) { |
| 645 | case VSB_8: |
| 646 | break; |
| 647 | case QAM_64: |
| 648 | case QAM_256: |
| 649 | break; |
| 650 | default: |
| 651 | return -EINVAL; |
| 652 | } |
| 653 | return 0; |
| 654 | } |
| 655 | |
| 656 | /* ------------------------------------------------------------------------ */ |
| 657 | |
| 658 | static int lgdt3306a_set_inversion(struct lgdt3306a_state *state, |
| 659 | int inversion) |
| 660 | { |
| 661 | int ret; |
| 662 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 663 | dbg_info("(%d)\n", inversion); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 664 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 665 | ret = lgdt3306a_set_reg_bit(state, 0x0002, 2, inversion ? 1 : 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 666 | return ret; |
| 667 | } |
| 668 | |
| 669 | static int lgdt3306a_set_inversion_auto(struct lgdt3306a_state *state, |
| 670 | int enabled) |
| 671 | { |
| 672 | int ret; |
| 673 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 674 | dbg_info("(%d)\n", enabled); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 675 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 676 | /* 0=Manual 1=Auto(QAM only) - SPECINVAUTO=0x04 */ |
| 677 | ret = lgdt3306a_set_reg_bit(state, 0x0002, 3, enabled); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 678 | return ret; |
| 679 | } |
| 680 | |
| 681 | static int lgdt3306a_spectral_inversion(struct lgdt3306a_state *state, |
| 682 | struct dtv_frontend_properties *p, |
| 683 | int inversion) |
| 684 | { |
| 685 | int ret = 0; |
| 686 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 687 | dbg_info("(%d)\n", inversion); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 688 | #if 0 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 689 | /* |
| 690 | * FGR - spectral_inversion defaults already set for VSB and QAM; |
| 691 | * can enable later if desired |
| 692 | */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 693 | |
| 694 | ret = lgdt3306a_set_inversion(state, inversion); |
| 695 | |
| 696 | switch (p->modulation) { |
| 697 | case VSB_8: |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 698 | /* Manual only for VSB */ |
| 699 | ret = lgdt3306a_set_inversion_auto(state, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 700 | break; |
| 701 | case QAM_64: |
| 702 | case QAM_256: |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 703 | /* Auto ok for QAM */ |
| 704 | ret = lgdt3306a_set_inversion_auto(state, 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 705 | break; |
| 706 | default: |
| 707 | ret = -EINVAL; |
| 708 | } |
| 709 | #endif |
| 710 | return ret; |
| 711 | } |
| 712 | |
| 713 | static int lgdt3306a_set_if(struct lgdt3306a_state *state, |
| 714 | struct dtv_frontend_properties *p) |
| 715 | { |
| 716 | int ret; |
| 717 | u16 if_freq_khz; |
| 718 | u8 nco1, nco2; |
| 719 | |
| 720 | switch (p->modulation) { |
| 721 | case VSB_8: |
| 722 | if_freq_khz = state->cfg->vsb_if_khz; |
| 723 | break; |
| 724 | case QAM_64: |
| 725 | case QAM_256: |
| 726 | if_freq_khz = state->cfg->qam_if_khz; |
| 727 | break; |
| 728 | default: |
| 729 | return -EINVAL; |
| 730 | } |
| 731 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 732 | switch (if_freq_khz) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 733 | default: |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 734 | pr_warn("IF=%d KHz is not supportted, 3250 assumed\n", |
| 735 | if_freq_khz); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 736 | /* fallthrough */ |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 737 | case 3250: /* 3.25Mhz */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 738 | nco1 = 0x34; |
| 739 | nco2 = 0x00; |
| 740 | break; |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 741 | case 3500: /* 3.50Mhz */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 742 | nco1 = 0x38; |
| 743 | nco2 = 0x00; |
| 744 | break; |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 745 | case 4000: /* 4.00Mhz */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 746 | nco1 = 0x40; |
| 747 | nco2 = 0x00; |
| 748 | break; |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 749 | case 5000: /* 5.00Mhz */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 750 | nco1 = 0x50; |
| 751 | nco2 = 0x00; |
| 752 | break; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 753 | case 5380: /* 5.38Mhz */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 754 | nco1 = 0x56; |
| 755 | nco2 = 0x14; |
| 756 | break; |
| 757 | } |
| 758 | ret = lgdt3306a_write_reg(state, 0x0010, nco1); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 759 | if (ret) |
| 760 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 761 | ret = lgdt3306a_write_reg(state, 0x0011, nco2); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 762 | if (ret) |
| 763 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 764 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 765 | dbg_info("if_freq=%d KHz->[%04x]\n", if_freq_khz, nco1<<8 | nco2); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 766 | |
| 767 | return 0; |
| 768 | } |
| 769 | |
| 770 | /* ------------------------------------------------------------------------ */ |
| 771 | |
| 772 | static int lgdt3306a_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 773 | { |
| 774 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 775 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 776 | if (state->cfg->deny_i2c_rptr) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 777 | dbg_info("deny_i2c_rptr=%d\n", state->cfg->deny_i2c_rptr); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 778 | return 0; |
| 779 | } |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 780 | dbg_info("(%d)\n", enable); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 781 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 782 | /* NI2CRPTEN=0x80 */ |
| 783 | return lgdt3306a_set_reg_bit(state, 0x0002, 7, enable ? 0 : 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | static int lgdt3306a_sleep(struct lgdt3306a_state *state) |
| 787 | { |
| 788 | int ret; |
| 789 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 790 | dbg_info("\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 791 | state->current_frequency = -1; /* force re-tune, when we wake */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 792 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 793 | ret = lgdt3306a_mpeg_tristate(state, 1); /* disable data bus */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 794 | if (lg_chkerr(ret)) |
| 795 | goto fail; |
| 796 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 797 | ret = lgdt3306a_power(state, 0); /* power down */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 798 | lg_chkerr(ret); |
| 799 | |
| 800 | fail: |
| 801 | return 0; |
| 802 | } |
| 803 | |
| 804 | static int lgdt3306a_fe_sleep(struct dvb_frontend *fe) |
| 805 | { |
| 806 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 807 | |
| 808 | return lgdt3306a_sleep(state); |
| 809 | } |
| 810 | |
| 811 | static int lgdt3306a_init(struct dvb_frontend *fe) |
| 812 | { |
| 813 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 814 | u8 val; |
| 815 | int ret; |
| 816 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 817 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 818 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 819 | /* 1. Normal operation mode */ |
| 820 | ret = lgdt3306a_set_reg_bit(state, 0x0001, 0, 1); /* SIMFASTENB=0x01 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 821 | if (lg_chkerr(ret)) |
| 822 | goto fail; |
| 823 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 824 | /* 2. Spectrum inversion auto detection (Not valid for VSB) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 825 | ret = lgdt3306a_set_inversion_auto(state, 0); |
| 826 | if (lg_chkerr(ret)) |
| 827 | goto fail; |
| 828 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 829 | /* 3. Spectrum inversion(According to the tuner configuration) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 830 | ret = lgdt3306a_set_inversion(state, 1); |
| 831 | if (lg_chkerr(ret)) |
| 832 | goto fail; |
| 833 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 834 | /* 4. Peak-to-peak voltage of ADC input signal */ |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 835 | |
| 836 | /* ADCSEL1V=0x80=1Vpp; 0x00=2Vpp */ |
| 837 | ret = lgdt3306a_set_reg_bit(state, 0x0004, 7, 1); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 838 | if (lg_chkerr(ret)) |
| 839 | goto fail; |
| 840 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 841 | /* 5. ADC output data capture clock phase */ |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 842 | |
| 843 | /* 0=same phase as ADC clock */ |
| 844 | ret = lgdt3306a_set_reg_bit(state, 0x0004, 2, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 845 | if (lg_chkerr(ret)) |
| 846 | goto fail; |
| 847 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 848 | /* 5a. ADC sampling clock source */ |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 849 | |
| 850 | /* ADCCLKPLLSEL=0x08; 0=use ext clock, not PLL */ |
| 851 | ret = lgdt3306a_set_reg_bit(state, 0x0004, 3, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 852 | if (lg_chkerr(ret)) |
| 853 | goto fail; |
| 854 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 855 | /* 6. Automatic PLL set */ |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 856 | |
| 857 | /* PLLSETAUTO=0x40; 0=off */ |
| 858 | ret = lgdt3306a_set_reg_bit(state, 0x0005, 6, 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 859 | if (lg_chkerr(ret)) |
| 860 | goto fail; |
| 861 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 862 | if (state->cfg->xtalMHz == 24) { /* 24MHz */ |
| 863 | /* 7. Frequency for PLL output(0x2564 for 192MHz for 24MHz) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 864 | ret = lgdt3306a_read_reg(state, 0x0005, &val); |
| 865 | if (lg_chkerr(ret)) |
| 866 | goto fail; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 867 | val &= 0xc0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 868 | val |= 0x25; |
| 869 | ret = lgdt3306a_write_reg(state, 0x0005, val); |
| 870 | if (lg_chkerr(ret)) |
| 871 | goto fail; |
| 872 | ret = lgdt3306a_write_reg(state, 0x0006, 0x64); |
| 873 | if (lg_chkerr(ret)) |
| 874 | goto fail; |
| 875 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 876 | /* 8. ADC sampling frequency(0x180000 for 24MHz sampling) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 877 | ret = lgdt3306a_read_reg(state, 0x000d, &val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 878 | if (lg_chkerr(ret)) |
| 879 | goto fail; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 880 | val &= 0xc0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 881 | val |= 0x18; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 882 | ret = lgdt3306a_write_reg(state, 0x000d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 883 | if (lg_chkerr(ret)) |
| 884 | goto fail; |
| 885 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 886 | } else if (state->cfg->xtalMHz == 25) { /* 25MHz */ |
| 887 | /* 7. Frequency for PLL output */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 888 | ret = lgdt3306a_read_reg(state, 0x0005, &val); |
| 889 | if (lg_chkerr(ret)) |
| 890 | goto fail; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 891 | val &= 0xc0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 892 | val |= 0x25; |
| 893 | ret = lgdt3306a_write_reg(state, 0x0005, val); |
| 894 | if (lg_chkerr(ret)) |
| 895 | goto fail; |
| 896 | ret = lgdt3306a_write_reg(state, 0x0006, 0x64); |
| 897 | if (lg_chkerr(ret)) |
| 898 | goto fail; |
| 899 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 900 | /* 8. ADC sampling frequency(0x190000 for 25MHz sampling) */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 901 | ret = lgdt3306a_read_reg(state, 0x000d, &val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 902 | if (lg_chkerr(ret)) |
| 903 | goto fail; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 904 | val &= 0xc0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 905 | val |= 0x19; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 906 | ret = lgdt3306a_write_reg(state, 0x000d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 907 | if (lg_chkerr(ret)) |
| 908 | goto fail; |
| 909 | } else { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 910 | pr_err("Bad xtalMHz=%d\n", state->cfg->xtalMHz); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 911 | } |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 912 | #if 0 |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 913 | ret = lgdt3306a_write_reg(state, 0x000e, 0x00); |
| 914 | ret = lgdt3306a_write_reg(state, 0x000f, 0x00); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 915 | #endif |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 916 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 917 | /* 9. Center frequency of input signal of ADC */ |
| 918 | ret = lgdt3306a_write_reg(state, 0x0010, 0x34); /* 3.25MHz */ |
| 919 | ret = lgdt3306a_write_reg(state, 0x0011, 0x00); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 920 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 921 | /* 10. Fixed gain error value */ |
| 922 | ret = lgdt3306a_write_reg(state, 0x0014, 0); /* gain error=0 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 923 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 924 | /* 10a. VSB TR BW gear shift initial step */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 925 | ret = lgdt3306a_read_reg(state, 0x103c, &val); |
| 926 | val &= 0x0f; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 927 | val |= 0x20; /* SAMGSAUTOSTL_V[3:0] = 2 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 928 | ret = lgdt3306a_write_reg(state, 0x103c, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 929 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 930 | /* 10b. Timing offset calibration in low temperature for VSB */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 931 | ret = lgdt3306a_read_reg(state, 0x103d, &val); |
| 932 | val &= 0xfc; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 933 | val |= 0x03; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 934 | ret = lgdt3306a_write_reg(state, 0x103d, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 935 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 936 | /* 10c. Timing offset calibration in low temperature for QAM */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 937 | ret = lgdt3306a_read_reg(state, 0x1036, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 938 | val &= 0xf0; |
| 939 | val |= 0x0c; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 940 | ret = lgdt3306a_write_reg(state, 0x1036, val); |
| 941 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 942 | /* 11. Using the imaginary part of CIR in CIR loading */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 943 | ret = lgdt3306a_read_reg(state, 0x211f, &val); |
| 944 | val &= 0xef; /* do not use imaginary of CIR */ |
| 945 | ret = lgdt3306a_write_reg(state, 0x211f, val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 946 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 947 | /* 12. Control of no signal detector function */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 948 | ret = lgdt3306a_read_reg(state, 0x2849, &val); |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 949 | val &= 0xef; /* NOUSENOSIGDET=0, enable no signal detector */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 950 | ret = lgdt3306a_write_reg(state, 0x2849, val); |
| 951 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 952 | /* FGR - put demod in some known mode */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 953 | ret = lgdt3306a_set_vsb(state); |
| 954 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 955 | /* 13. TP stream format */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 956 | ret = lgdt3306a_mpeg_mode(state, state->cfg->mpeg_mode); |
| 957 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 958 | /* 14. disable output buses */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 959 | ret = lgdt3306a_mpeg_tristate(state, 1); |
| 960 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 961 | /* 15. Sleep (in reset) */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 962 | ret = lgdt3306a_sleep(state); |
| 963 | lg_chkerr(ret); |
| 964 | |
| 965 | fail: |
| 966 | return ret; |
| 967 | } |
| 968 | |
| 969 | static int lgdt3306a_set_parameters(struct dvb_frontend *fe) |
| 970 | { |
| 971 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 972 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 973 | int ret; |
| 974 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 975 | dbg_info("(%d, %d)\n", p->frequency, p->modulation); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 976 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 977 | if (state->current_frequency == p->frequency && |
| 978 | state->current_modulation == p->modulation) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 979 | dbg_info(" (already set, skipping ...)\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 980 | return 0; |
| 981 | } |
| 982 | state->current_frequency = -1; |
| 983 | state->current_modulation = -1; |
| 984 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 985 | ret = lgdt3306a_power(state, 1); /* power up */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 986 | if (lg_chkerr(ret)) |
| 987 | goto fail; |
| 988 | |
| 989 | if (fe->ops.tuner_ops.set_params) { |
| 990 | ret = fe->ops.tuner_ops.set_params(fe); |
| 991 | if (fe->ops.i2c_gate_ctrl) |
| 992 | fe->ops.i2c_gate_ctrl(fe, 0); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 993 | #if 0 |
| 994 | if (lg_chkerr(ret)) |
| 995 | goto fail; |
| 996 | state->current_frequency = p->frequency; |
| 997 | #endif |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 998 | } |
| 999 | |
| 1000 | ret = lgdt3306a_set_modulation(state, p); |
| 1001 | if (lg_chkerr(ret)) |
| 1002 | goto fail; |
| 1003 | |
| 1004 | ret = lgdt3306a_agc_setup(state, p); |
| 1005 | if (lg_chkerr(ret)) |
| 1006 | goto fail; |
| 1007 | |
| 1008 | ret = lgdt3306a_set_if(state, p); |
| 1009 | if (lg_chkerr(ret)) |
| 1010 | goto fail; |
| 1011 | |
| 1012 | ret = lgdt3306a_spectral_inversion(state, p, |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1013 | state->cfg->spectral_inversion ? 1 : 0); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1014 | if (lg_chkerr(ret)) |
| 1015 | goto fail; |
| 1016 | |
| 1017 | ret = lgdt3306a_mpeg_mode(state, state->cfg->mpeg_mode); |
| 1018 | if (lg_chkerr(ret)) |
| 1019 | goto fail; |
| 1020 | |
| 1021 | ret = lgdt3306a_mpeg_mode_polarity(state, |
| 1022 | state->cfg->tpclk_edge, |
| 1023 | state->cfg->tpvalid_polarity); |
| 1024 | if (lg_chkerr(ret)) |
| 1025 | goto fail; |
| 1026 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1027 | ret = lgdt3306a_mpeg_tristate(state, 0); /* enable data bus */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1028 | if (lg_chkerr(ret)) |
| 1029 | goto fail; |
| 1030 | |
| 1031 | ret = lgdt3306a_soft_reset(state); |
| 1032 | if (lg_chkerr(ret)) |
| 1033 | goto fail; |
| 1034 | |
| 1035 | #ifdef DBG_DUMP |
| 1036 | lgdt3306a_DumpAllRegs(state); |
| 1037 | #endif |
| 1038 | state->current_frequency = p->frequency; |
| 1039 | fail: |
| 1040 | return ret; |
| 1041 | } |
| 1042 | |
| 1043 | static int lgdt3306a_get_frontend(struct dvb_frontend *fe) |
| 1044 | { |
| 1045 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 1046 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
| 1047 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1048 | dbg_info("(%u, %d)\n", |
| 1049 | state->current_frequency, state->current_modulation); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1050 | |
| 1051 | p->modulation = state->current_modulation; |
| 1052 | p->frequency = state->current_frequency; |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | static enum dvbfe_algo lgdt3306a_get_frontend_algo(struct dvb_frontend *fe) |
| 1057 | { |
| 1058 | #if 1 |
| 1059 | return DVBFE_ALGO_CUSTOM; |
| 1060 | #else |
| 1061 | return DVBFE_ALGO_HW; |
| 1062 | #endif |
| 1063 | } |
| 1064 | |
| 1065 | /* ------------------------------------------------------------------------ */ |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1066 | static int lgdt3306a_monitor_vsb(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1067 | { |
| 1068 | u8 val; |
| 1069 | int ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1070 | u8 snrRef, maxPowerMan, nCombDet; |
| 1071 | u16 fbDlyCir; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1072 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1073 | ret = lgdt3306a_read_reg(state, 0x21a1, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1074 | if (ret) |
| 1075 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1076 | snrRef = val & 0x3f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1077 | |
| 1078 | ret = lgdt3306a_read_reg(state, 0x2185, &maxPowerMan); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1079 | if (ret) |
| 1080 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1081 | |
| 1082 | ret = lgdt3306a_read_reg(state, 0x2191, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1083 | if (ret) |
| 1084 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1085 | nCombDet = (val & 0x80) >> 7; |
| 1086 | |
| 1087 | ret = lgdt3306a_read_reg(state, 0x2180, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1088 | if (ret) |
| 1089 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1090 | fbDlyCir = (val & 0x03) << 8; |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1091 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1092 | ret = lgdt3306a_read_reg(state, 0x2181, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1093 | if (ret) |
| 1094 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1095 | fbDlyCir |= val; |
| 1096 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1097 | dbg_info("snrRef=%d maxPowerMan=0x%x nCombDet=%d fbDlyCir=0x%x\n", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1098 | snrRef, maxPowerMan, nCombDet, fbDlyCir); |
| 1099 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1100 | /* Carrier offset sub loop bandwidth */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1101 | ret = lgdt3306a_read_reg(state, 0x1061, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1102 | if (ret) |
| 1103 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1104 | val &= 0xf8; |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1105 | if ((snrRef > 18) && (maxPowerMan > 0x68) |
| 1106 | && (nCombDet == 0x01) |
| 1107 | && ((fbDlyCir == 0x03FF) || (fbDlyCir < 0x6C))) { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1108 | /* SNR is over 18dB and no ghosting */ |
| 1109 | val |= 0x00; /* final bandwidth = 0 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1110 | } else { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1111 | val |= 0x04; /* final bandwidth = 4 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1112 | } |
| 1113 | ret = lgdt3306a_write_reg(state, 0x1061, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1114 | if (ret) |
| 1115 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1116 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1117 | /* Adjust Notch Filter */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1118 | ret = lgdt3306a_read_reg(state, 0x0024, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1119 | if (ret) |
| 1120 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1121 | val &= 0x0f; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1122 | if (nCombDet == 0) { /* Turn on the Notch Filter */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1123 | val |= 0x50; |
| 1124 | } |
| 1125 | ret = lgdt3306a_write_reg(state, 0x0024, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1126 | if (ret) |
| 1127 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1128 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1129 | /* VSB Timing Recovery output normalization */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1130 | ret = lgdt3306a_read_reg(state, 0x103d, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1131 | if (ret) |
| 1132 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1133 | val &= 0xcf; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1134 | val |= 0x20; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1135 | ret = lgdt3306a_write_reg(state, 0x103d, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1136 | |
| 1137 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1138 | } |
| 1139 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1140 | static enum lgdt3306a_modulation |
| 1141 | lgdt3306a_check_oper_mode(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1142 | { |
| 1143 | u8 val = 0; |
| 1144 | int ret; |
| 1145 | |
| 1146 | ret = lgdt3306a_read_reg(state, 0x0081, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1147 | if (ret) |
| 1148 | goto err; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1149 | |
| 1150 | if (val & 0x80) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1151 | dbg_info("VSB\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1152 | return LG3306_VSB; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1153 | } |
Michael Ira Krufky | c714efe | 2014-08-03 14:51:49 -0300 | [diff] [blame] | 1154 | if (val & 0x08) { |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1155 | ret = lgdt3306a_read_reg(state, 0x00a6, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1156 | if (ret) |
| 1157 | goto err; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1158 | val = val >> 2; |
| 1159 | if (val & 0x01) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1160 | dbg_info("QAM256\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1161 | return LG3306_QAM256; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1162 | } |
Mauro Carvalho Chehab | b4e43e9 | 2014-10-28 12:05:35 -0200 | [diff] [blame] | 1163 | dbg_info("QAM64\n"); |
| 1164 | return LG3306_QAM64; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1165 | } |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1166 | err: |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1167 | pr_warn("UNKNOWN\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1168 | return LG3306_UNKNOWN_MODE; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1169 | } |
| 1170 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1171 | static enum lgdt3306a_lock_status |
| 1172 | lgdt3306a_check_lock_status(struct lgdt3306a_state *state, |
| 1173 | enum lgdt3306a_lock_check whatLock) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1174 | { |
| 1175 | u8 val = 0; |
| 1176 | int ret; |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1177 | enum lgdt3306a_modulation modeOper; |
| 1178 | enum lgdt3306a_lock_status lockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1179 | |
| 1180 | modeOper = LG3306_UNKNOWN_MODE; |
| 1181 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1182 | switch (whatLock) { |
| 1183 | case LG3306_SYNC_LOCK: |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1184 | { |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1185 | ret = lgdt3306a_read_reg(state, 0x00a6, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1186 | if (ret) |
| 1187 | return ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1188 | |
| 1189 | if ((val & 0x80) == 0x80) |
| 1190 | lockStatus = LG3306_LOCK; |
| 1191 | else |
| 1192 | lockStatus = LG3306_UNLOCK; |
| 1193 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1194 | dbg_info("SYNC_LOCK=%x\n", lockStatus); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1195 | break; |
| 1196 | } |
| 1197 | case LG3306_AGC_LOCK: |
| 1198 | { |
| 1199 | ret = lgdt3306a_read_reg(state, 0x0080, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1200 | if (ret) |
| 1201 | return ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1202 | |
| 1203 | if ((val & 0x40) == 0x40) |
| 1204 | lockStatus = LG3306_LOCK; |
| 1205 | else |
| 1206 | lockStatus = LG3306_UNLOCK; |
| 1207 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1208 | dbg_info("AGC_LOCK=%x\n", lockStatus); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1209 | break; |
| 1210 | } |
| 1211 | case LG3306_TR_LOCK: |
| 1212 | { |
| 1213 | modeOper = lgdt3306a_check_oper_mode(state); |
| 1214 | if ((modeOper == LG3306_QAM64) || (modeOper == LG3306_QAM256)) { |
| 1215 | ret = lgdt3306a_read_reg(state, 0x1094, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1216 | if (ret) |
| 1217 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1218 | |
| 1219 | if ((val & 0x80) == 0x80) |
| 1220 | lockStatus = LG3306_LOCK; |
| 1221 | else |
| 1222 | lockStatus = LG3306_UNLOCK; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1223 | } else |
| 1224 | lockStatus = LG3306_UNKNOWN_LOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1225 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1226 | dbg_info("TR_LOCK=%x\n", lockStatus); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1227 | break; |
| 1228 | } |
| 1229 | case LG3306_FEC_LOCK: |
| 1230 | { |
| 1231 | modeOper = lgdt3306a_check_oper_mode(state); |
| 1232 | if ((modeOper == LG3306_QAM64) || (modeOper == LG3306_QAM256)) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1233 | ret = lgdt3306a_read_reg(state, 0x0080, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1234 | if (ret) |
| 1235 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1236 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1237 | if ((val & 0x10) == 0x10) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1238 | lockStatus = LG3306_LOCK; |
| 1239 | else |
| 1240 | lockStatus = LG3306_UNLOCK; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1241 | } else |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1242 | lockStatus = LG3306_UNKNOWN_LOCK; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1243 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1244 | dbg_info("FEC_LOCK=%x\n", lockStatus); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1245 | break; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1246 | } |
| 1247 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1248 | default: |
| 1249 | lockStatus = LG3306_UNKNOWN_LOCK; |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1250 | pr_warn("UNKNOWN whatLock=%d\n", whatLock); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | return lockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1255 | } |
| 1256 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1257 | static enum lgdt3306a_neverlock_status |
| 1258 | lgdt3306a_check_neverlock_status(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1259 | { |
| 1260 | u8 val = 0; |
| 1261 | int ret; |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1262 | enum lgdt3306a_neverlock_status lockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1263 | |
| 1264 | ret = lgdt3306a_read_reg(state, 0x0080, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1265 | if (ret) |
| 1266 | return ret; |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1267 | lockStatus = (enum lgdt3306a_neverlock_status)(val & 0x03); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1268 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1269 | dbg_info("NeverLock=%d", lockStatus); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1270 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1271 | return lockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1272 | } |
| 1273 | |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1274 | static int lgdt3306a_pre_monitoring(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1275 | { |
| 1276 | u8 val = 0; |
| 1277 | int ret; |
| 1278 | u8 currChDiffACQ, snrRef, mainStrong, aiccrejStatus; |
| 1279 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1280 | /* Channel variation */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1281 | ret = lgdt3306a_read_reg(state, 0x21bc, &currChDiffACQ); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1282 | if (ret) |
| 1283 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1284 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1285 | /* SNR of Frame sync */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1286 | ret = lgdt3306a_read_reg(state, 0x21a1, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1287 | if (ret) |
| 1288 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1289 | snrRef = val & 0x3f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1290 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1291 | /* Strong Main CIR */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1292 | ret = lgdt3306a_read_reg(state, 0x2199, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1293 | if (ret) |
| 1294 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1295 | mainStrong = (val & 0x40) >> 6; |
| 1296 | |
| 1297 | ret = lgdt3306a_read_reg(state, 0x0090, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1298 | if (ret) |
| 1299 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1300 | aiccrejStatus = (val & 0xf0) >> 4; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1301 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1302 | dbg_info("snrRef=%d mainStrong=%d aiccrejStatus=%d currChDiffACQ=0x%x\n", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1303 | snrRef, mainStrong, aiccrejStatus, currChDiffACQ); |
| 1304 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1305 | #if 0 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1306 | /* Dynamic ghost exists */ |
| 1307 | if ((mainStrong == 0) && (currChDiffACQ > 0x70)) |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1308 | #endif |
| 1309 | if (mainStrong == 0) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1310 | ret = lgdt3306a_read_reg(state, 0x2135, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1311 | if (ret) |
| 1312 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1313 | val &= 0x0f; |
| 1314 | val |= 0xa0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1315 | ret = lgdt3306a_write_reg(state, 0x2135, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1316 | if (ret) |
| 1317 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1318 | |
| 1319 | ret = lgdt3306a_read_reg(state, 0x2141, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1320 | if (ret) |
| 1321 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1322 | val &= 0x3f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1323 | val |= 0x80; |
| 1324 | ret = lgdt3306a_write_reg(state, 0x2141, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1325 | if (ret) |
| 1326 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1327 | |
| 1328 | ret = lgdt3306a_write_reg(state, 0x2122, 0x70); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1329 | if (ret) |
| 1330 | return ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1331 | } else { /* Weak ghost or static channel */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1332 | ret = lgdt3306a_read_reg(state, 0x2135, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1333 | if (ret) |
| 1334 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1335 | val &= 0x0f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1336 | val |= 0x70; |
| 1337 | ret = lgdt3306a_write_reg(state, 0x2135, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1338 | if (ret) |
| 1339 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1340 | |
| 1341 | ret = lgdt3306a_read_reg(state, 0x2141, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1342 | if (ret) |
| 1343 | return ret; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1344 | val &= 0x3f; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1345 | val |= 0x40; |
| 1346 | ret = lgdt3306a_write_reg(state, 0x2141, val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1347 | if (ret) |
| 1348 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1349 | |
| 1350 | ret = lgdt3306a_write_reg(state, 0x2122, 0x40); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1351 | if (ret) |
| 1352 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1353 | } |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1354 | return 0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1355 | } |
| 1356 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1357 | static enum lgdt3306a_lock_status |
| 1358 | lgdt3306a_sync_lock_poll(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1359 | { |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1360 | enum lgdt3306a_lock_status syncLockStatus = LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1361 | int i; |
| 1362 | |
| 1363 | for (i = 0; i < 2; i++) { |
| 1364 | msleep(30); |
| 1365 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1366 | syncLockStatus = lgdt3306a_check_lock_status(state, |
| 1367 | LG3306_SYNC_LOCK); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1368 | |
| 1369 | if (syncLockStatus == LG3306_LOCK) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1370 | dbg_info("locked(%d)\n", i); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1371 | return LG3306_LOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1372 | } |
| 1373 | } |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1374 | dbg_info("not locked\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1375 | return LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1376 | } |
| 1377 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1378 | static enum lgdt3306a_lock_status |
| 1379 | lgdt3306a_fec_lock_poll(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1380 | { |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1381 | enum lgdt3306a_lock_status FECLockStatus = LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1382 | int i; |
| 1383 | |
| 1384 | for (i = 0; i < 2; i++) { |
| 1385 | msleep(30); |
| 1386 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1387 | FECLockStatus = lgdt3306a_check_lock_status(state, |
| 1388 | LG3306_FEC_LOCK); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1389 | |
| 1390 | if (FECLockStatus == LG3306_LOCK) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1391 | dbg_info("locked(%d)\n", i); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1392 | return FECLockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1393 | } |
| 1394 | } |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1395 | dbg_info("not locked\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1396 | return FECLockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1397 | } |
| 1398 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1399 | static enum lgdt3306a_neverlock_status |
| 1400 | lgdt3306a_neverlock_poll(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1401 | { |
Michael Ira Krufky | f883d60 | 2014-08-03 15:29:04 -0300 | [diff] [blame] | 1402 | enum lgdt3306a_neverlock_status NLLockStatus = LG3306_NL_FAIL; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1403 | int i; |
| 1404 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1405 | for (i = 0; i < 5; i++) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1406 | msleep(30); |
| 1407 | |
| 1408 | NLLockStatus = lgdt3306a_check_neverlock_status(state); |
| 1409 | |
| 1410 | if (NLLockStatus == LG3306_NL_LOCK) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1411 | dbg_info("NL_LOCK(%d)\n", i); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1412 | return NLLockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1413 | } |
| 1414 | } |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1415 | dbg_info("NLLockStatus=%d\n", NLLockStatus); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1416 | return NLLockStatus; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | static u8 lgdt3306a_get_packet_error(struct lgdt3306a_state *state) |
| 1420 | { |
| 1421 | u8 val; |
| 1422 | int ret; |
| 1423 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1424 | ret = lgdt3306a_read_reg(state, 0x00fa, &val); |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1425 | if (ret) |
| 1426 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1427 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1428 | return val; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1429 | } |
| 1430 | |
Mauro Carvalho Chehab | 9369fe0 | 2014-10-28 12:30:44 -0200 | [diff] [blame] | 1431 | static const u32 valx_x10[] = { |
| 1432 | 10, 11, 13, 15, 17, 20, 25, 33, 41, 50, 59, 73, 87, 100 |
| 1433 | }; |
| 1434 | static const u32 log10x_x1000[] = { |
Mauro Carvalho Chehab | 95f22c5 | 2014-10-28 12:40:20 -0200 | [diff] [blame] | 1435 | 0, 41, 114, 176, 230, 301, 398, 518, 613, 699, 771, 863, 939, 1000 |
Mauro Carvalho Chehab | 9369fe0 | 2014-10-28 12:30:44 -0200 | [diff] [blame] | 1436 | }; |
| 1437 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1438 | static u32 log10_x1000(u32 x) |
| 1439 | { |
Mauro Carvalho Chehab | a132fef | 2014-10-28 11:07:03 -0200 | [diff] [blame] | 1440 | u32 diff_val, step_val, step_log10; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1441 | u32 log_val = 0; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1442 | u32 i; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1443 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1444 | if (x <= 0) |
| 1445 | return -1000000; /* signal error */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1446 | |
Mauro Carvalho Chehab | b4e43e9 | 2014-10-28 12:05:35 -0200 | [diff] [blame] | 1447 | if (x == 10) |
| 1448 | return 0; /* log(1)=0 */ |
| 1449 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1450 | if (x < 10) { |
| 1451 | while (x < 10) { |
| 1452 | x = x * 10; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1453 | log_val--; |
| 1454 | } |
Mauro Carvalho Chehab | b4e43e9 | 2014-10-28 12:05:35 -0200 | [diff] [blame] | 1455 | } else { /* x > 10 */ |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1456 | while (x >= 100) { |
| 1457 | x = x / 10; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1458 | log_val++; |
| 1459 | } |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1460 | } |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1461 | log_val *= 1000; |
| 1462 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1463 | if (x == 10) /* was our input an exact multiple of 10 */ |
| 1464 | return log_val; /* don't need to interpolate */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1465 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1466 | /* find our place on the log curve */ |
Mauro Carvalho Chehab | 9369fe0 | 2014-10-28 12:30:44 -0200 | [diff] [blame] | 1467 | for (i = 1; i < ARRAY_SIZE(valx_x10); i++) { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1468 | if (valx_x10[i] >= x) |
| 1469 | break; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1470 | } |
Mauro Carvalho Chehab | 9369fe0 | 2014-10-28 12:30:44 -0200 | [diff] [blame] | 1471 | if (i == ARRAY_SIZE(valx_x10)) |
Mauro Carvalho Chehab | a132fef | 2014-10-28 11:07:03 -0200 | [diff] [blame] | 1472 | return log_val + log10x_x1000[i - 1]; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1473 | |
Mauro Carvalho Chehab | a132fef | 2014-10-28 11:07:03 -0200 | [diff] [blame] | 1474 | diff_val = x - valx_x10[i-1]; |
| 1475 | step_val = valx_x10[i] - valx_x10[i - 1]; |
| 1476 | step_log10 = log10x_x1000[i] - log10x_x1000[i - 1]; |
| 1477 | |
| 1478 | /* do a linear interpolation to get in-between values */ |
| 1479 | return log_val + log10x_x1000[i - 1] + |
| 1480 | ((diff_val*step_log10) / step_val); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | static u32 lgdt3306a_calculate_snr_x100(struct lgdt3306a_state *state) |
| 1484 | { |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 1485 | u32 mse; /* Mean-Square Error */ |
| 1486 | u32 pwr; /* Constelation power */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1487 | u32 snr_x100; |
| 1488 | |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1489 | mse = (read_reg(state, 0x00ec) << 8) | |
| 1490 | (read_reg(state, 0x00ed)); |
| 1491 | pwr = (read_reg(state, 0x00e8) << 8) | |
| 1492 | (read_reg(state, 0x00e9)); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1493 | |
| 1494 | if (mse == 0) /* no signal */ |
| 1495 | return 0; |
| 1496 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1497 | snr_x100 = log10_x1000((pwr * 10000) / mse) - 3000; |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1498 | dbg_info("mse=%u, pwr=%u, snr_x100=%d\n", mse, pwr, snr_x100); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1499 | |
| 1500 | return snr_x100; |
| 1501 | } |
| 1502 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1503 | static enum lgdt3306a_lock_status |
| 1504 | lgdt3306a_vsb_lock_poll(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1505 | { |
Mauro Carvalho Chehab | e2c47fa | 2014-10-28 11:27:34 -0200 | [diff] [blame] | 1506 | int ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1507 | u8 cnt = 0; |
| 1508 | u8 packet_error; |
| 1509 | u32 snr; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1510 | |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1511 | for (cnt = 0; cnt < 10; cnt++) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1512 | if (lgdt3306a_sync_lock_poll(state) == LG3306_UNLOCK) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1513 | dbg_info("no sync lock!\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1514 | return LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1515 | } |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1516 | |
| 1517 | msleep(20); |
| 1518 | ret = lgdt3306a_pre_monitoring(state); |
| 1519 | if (ret) |
| 1520 | break; |
| 1521 | |
| 1522 | packet_error = lgdt3306a_get_packet_error(state); |
| 1523 | snr = lgdt3306a_calculate_snr_x100(state); |
| 1524 | dbg_info("cnt=%d errors=%d snr=%d\n", cnt, packet_error, snr); |
| 1525 | |
| 1526 | if ((snr >= 1500) && (packet_error < 0xff)) |
| 1527 | return LG3306_LOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1528 | } |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1529 | |
| 1530 | dbg_info("not locked!\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1531 | return LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1532 | } |
| 1533 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1534 | static enum lgdt3306a_lock_status |
| 1535 | lgdt3306a_qam_lock_poll(struct lgdt3306a_state *state) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1536 | { |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1537 | u8 cnt; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1538 | u8 packet_error; |
| 1539 | u32 snr; |
| 1540 | |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1541 | for (cnt = 0; cnt < 10; cnt++) { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1542 | if (lgdt3306a_fec_lock_poll(state) == LG3306_UNLOCK) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1543 | dbg_info("no fec lock!\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1544 | return LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1545 | } |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1546 | |
| 1547 | msleep(20); |
| 1548 | |
| 1549 | packet_error = lgdt3306a_get_packet_error(state); |
| 1550 | snr = lgdt3306a_calculate_snr_x100(state); |
| 1551 | dbg_info("cnt=%d errors=%d snr=%d\n", cnt, packet_error, snr); |
| 1552 | |
| 1553 | if ((snr >= 1500) && (packet_error < 0xff)) |
| 1554 | return LG3306_LOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1555 | } |
Mauro Carvalho Chehab | b1a88c7 | 2014-10-28 12:00:48 -0200 | [diff] [blame] | 1556 | |
| 1557 | dbg_info("not locked!\n"); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1558 | return LG3306_UNLOCK; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1559 | } |
| 1560 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1561 | static int lgdt3306a_read_status(struct dvb_frontend *fe, |
| 1562 | enum fe_status *status) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1563 | { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1564 | struct lgdt3306a_state *state = fe->demodulator_priv; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1565 | u16 strength = 0; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1566 | int ret = 0; |
| 1567 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1568 | if (fe->ops.tuner_ops.get_rf_strength) { |
| 1569 | ret = fe->ops.tuner_ops.get_rf_strength(fe, &strength); |
Mauro Carvalho Chehab | c989764 | 2014-10-28 12:07:52 -0200 | [diff] [blame] | 1570 | if (ret == 0) |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1571 | dbg_info("strength=%d\n", strength); |
Mauro Carvalho Chehab | c989764 | 2014-10-28 12:07:52 -0200 | [diff] [blame] | 1572 | else |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1573 | dbg_info("fe->ops.tuner_ops.get_rf_strength() failed\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1574 | } |
| 1575 | |
| 1576 | *status = 0; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1577 | if (lgdt3306a_neverlock_poll(state) == LG3306_NL_LOCK) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1578 | *status |= FE_HAS_SIGNAL; |
| 1579 | *status |= FE_HAS_CARRIER; |
| 1580 | |
| 1581 | switch (state->current_modulation) { |
| 1582 | case QAM_256: |
| 1583 | case QAM_64: |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1584 | if (lgdt3306a_qam_lock_poll(state) == LG3306_LOCK) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1585 | *status |= FE_HAS_VITERBI; |
| 1586 | *status |= FE_HAS_SYNC; |
| 1587 | |
| 1588 | *status |= FE_HAS_LOCK; |
| 1589 | } |
| 1590 | break; |
| 1591 | case VSB_8: |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1592 | if (lgdt3306a_vsb_lock_poll(state) == LG3306_LOCK) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1593 | *status |= FE_HAS_VITERBI; |
| 1594 | *status |= FE_HAS_SYNC; |
| 1595 | |
| 1596 | *status |= FE_HAS_LOCK; |
| 1597 | |
Mauro Carvalho Chehab | ee0133e | 2014-10-28 11:21:48 -0200 | [diff] [blame] | 1598 | ret = lgdt3306a_monitor_vsb(state); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1599 | } |
| 1600 | break; |
| 1601 | default: |
| 1602 | ret = -EINVAL; |
| 1603 | } |
| 1604 | } |
| 1605 | return ret; |
| 1606 | } |
| 1607 | |
| 1608 | |
| 1609 | static int lgdt3306a_read_snr(struct dvb_frontend *fe, u16 *snr) |
| 1610 | { |
| 1611 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 1612 | |
| 1613 | state->snr = lgdt3306a_calculate_snr_x100(state); |
| 1614 | /* report SNR in dB * 10 */ |
| 1615 | *snr = state->snr/10; |
| 1616 | |
| 1617 | return 0; |
| 1618 | } |
| 1619 | |
| 1620 | static int lgdt3306a_read_signal_strength(struct dvb_frontend *fe, |
| 1621 | u16 *strength) |
| 1622 | { |
| 1623 | /* |
| 1624 | * Calculate some sort of "strength" from SNR |
| 1625 | */ |
| 1626 | struct lgdt3306a_state *state = fe->demodulator_priv; |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 1627 | u16 snr; /* snr_x10 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1628 | int ret; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1629 | u32 ref_snr; /* snr*100 */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1630 | u32 str; |
| 1631 | |
| 1632 | *strength = 0; |
| 1633 | |
| 1634 | switch (state->current_modulation) { |
| 1635 | case VSB_8: |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1636 | ref_snr = 1600; /* 16dB */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1637 | break; |
| 1638 | case QAM_64: |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1639 | ref_snr = 2200; /* 22dB */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1640 | break; |
| 1641 | case QAM_256: |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1642 | ref_snr = 2800; /* 28dB */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1643 | break; |
| 1644 | default: |
| 1645 | return -EINVAL; |
| 1646 | } |
| 1647 | |
| 1648 | ret = fe->ops.read_snr(fe, &snr); |
| 1649 | if (lg_chkerr(ret)) |
| 1650 | goto fail; |
| 1651 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1652 | if (state->snr <= (ref_snr - 100)) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1653 | str = 0; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1654 | else if (state->snr <= ref_snr) |
| 1655 | str = (0xffff * 65) / 100; /* 65% */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1656 | else { |
| 1657 | str = state->snr - ref_snr; |
| 1658 | str /= 50; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1659 | str += 78; /* 78%-100% */ |
| 1660 | if (str > 100) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1661 | str = 100; |
| 1662 | str = (0xffff * str) / 100; |
| 1663 | } |
| 1664 | *strength = (u16)str; |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1665 | dbg_info("strength=%u\n", *strength); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1666 | |
| 1667 | fail: |
| 1668 | return ret; |
| 1669 | } |
| 1670 | |
| 1671 | /* ------------------------------------------------------------------------ */ |
| 1672 | |
| 1673 | static int lgdt3306a_read_ber(struct dvb_frontend *fe, u32 *ber) |
| 1674 | { |
| 1675 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 1676 | u32 tmp; |
| 1677 | |
| 1678 | *ber = 0; |
| 1679 | #if 1 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1680 | /* FGR - FIXME - I don't know what value is expected by dvb_core |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1681 | * what is the scale of the value?? */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1682 | tmp = read_reg(state, 0x00fc); /* NBERVALUE[24-31] */ |
| 1683 | tmp = (tmp << 8) | read_reg(state, 0x00fd); /* NBERVALUE[16-23] */ |
| 1684 | tmp = (tmp << 8) | read_reg(state, 0x00fe); /* NBERVALUE[8-15] */ |
| 1685 | tmp = (tmp << 8) | read_reg(state, 0x00ff); /* NBERVALUE[0-7] */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1686 | *ber = tmp; |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1687 | dbg_info("ber=%u\n", tmp); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1688 | #endif |
| 1689 | return 0; |
| 1690 | } |
| 1691 | |
| 1692 | static int lgdt3306a_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
| 1693 | { |
| 1694 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 1695 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1696 | *ucblocks = 0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1697 | #if 1 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1698 | /* FGR - FIXME - I don't know what value is expected by dvb_core |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1699 | * what happens when value wraps? */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1700 | *ucblocks = read_reg(state, 0x00f4); /* TPIFTPERRCNT[0-7] */ |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1701 | dbg_info("ucblocks=%u\n", *ucblocks); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1702 | #endif |
| 1703 | |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1707 | static int lgdt3306a_tune(struct dvb_frontend *fe, bool re_tune, |
| 1708 | unsigned int mode_flags, unsigned int *delay, |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1709 | enum fe_status *status) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1710 | { |
| 1711 | int ret = 0; |
| 1712 | struct lgdt3306a_state *state = fe->demodulator_priv; |
| 1713 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1714 | dbg_info("re_tune=%u\n", re_tune); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1715 | |
| 1716 | if (re_tune) { |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1717 | state->current_frequency = -1; /* force re-tune */ |
Michael Ira Krufky | ae21e44 | 2014-08-03 15:18:23 -0300 | [diff] [blame] | 1718 | ret = lgdt3306a_set_parameters(fe); |
| 1719 | if (ret != 0) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1720 | return ret; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1721 | } |
| 1722 | *delay = 125; |
| 1723 | ret = lgdt3306a_read_status(fe, status); |
| 1724 | |
| 1725 | return ret; |
| 1726 | } |
| 1727 | |
| 1728 | static int lgdt3306a_get_tune_settings(struct dvb_frontend *fe, |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1729 | struct dvb_frontend_tune_settings |
| 1730 | *fe_tune_settings) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1731 | { |
| 1732 | fe_tune_settings->min_delay_ms = 100; |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1733 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1734 | return 0; |
| 1735 | } |
| 1736 | |
| 1737 | static int lgdt3306a_search(struct dvb_frontend *fe) |
| 1738 | { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 1739 | enum fe_status status = 0; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1740 | int i, ret; |
| 1741 | |
| 1742 | /* set frontend */ |
| 1743 | ret = lgdt3306a_set_parameters(fe); |
| 1744 | if (ret) |
| 1745 | goto error; |
| 1746 | |
| 1747 | /* wait frontend lock */ |
| 1748 | for (i = 20; i > 0; i--) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1749 | dbg_info(": loop=%d\n", i); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1750 | msleep(50); |
| 1751 | ret = lgdt3306a_read_status(fe, &status); |
| 1752 | if (ret) |
| 1753 | goto error; |
| 1754 | |
| 1755 | if (status & FE_HAS_LOCK) |
| 1756 | break; |
| 1757 | } |
| 1758 | |
| 1759 | /* check if we have a valid signal */ |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1760 | if (status & FE_HAS_LOCK) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1761 | return DVBFE_ALGO_SEARCH_SUCCESS; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1762 | else |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1763 | return DVBFE_ALGO_SEARCH_AGAIN; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1764 | |
| 1765 | error: |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1766 | dbg_info("failed (%d)\n", ret); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1767 | return DVBFE_ALGO_SEARCH_ERROR; |
| 1768 | } |
| 1769 | |
| 1770 | static void lgdt3306a_release(struct dvb_frontend *fe) |
| 1771 | { |
| 1772 | struct lgdt3306a_state *state = fe->demodulator_priv; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1773 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1774 | dbg_info("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1775 | kfree(state); |
| 1776 | } |
| 1777 | |
| 1778 | static struct dvb_frontend_ops lgdt3306a_ops; |
| 1779 | |
| 1780 | struct dvb_frontend *lgdt3306a_attach(const struct lgdt3306a_config *config, |
Mauro Carvalho Chehab | c43e651 | 2014-10-28 10:56:10 -0200 | [diff] [blame] | 1781 | struct i2c_adapter *i2c_adap) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1782 | { |
| 1783 | struct lgdt3306a_state *state = NULL; |
| 1784 | int ret; |
| 1785 | u8 val; |
| 1786 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1787 | dbg_info("(%d-%04x)\n", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1788 | i2c_adap ? i2c_adapter_id(i2c_adap) : 0, |
| 1789 | config ? config->i2c_addr : 0); |
| 1790 | |
| 1791 | state = kzalloc(sizeof(struct lgdt3306a_state), GFP_KERNEL); |
| 1792 | if (state == NULL) |
| 1793 | goto fail; |
| 1794 | |
| 1795 | state->cfg = config; |
| 1796 | state->i2c_adap = i2c_adap; |
| 1797 | |
| 1798 | memcpy(&state->frontend.ops, &lgdt3306a_ops, |
| 1799 | sizeof(struct dvb_frontend_ops)); |
| 1800 | state->frontend.demodulator_priv = state; |
| 1801 | |
| 1802 | /* verify that we're talking to a lg3306a */ |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1803 | /* FGR - NOTE - there is no obvious ChipId to check; we check |
| 1804 | * some "known" bits after reset, but it's still just a guess */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1805 | ret = lgdt3306a_read_reg(state, 0x0000, &val); |
| 1806 | if (lg_chkerr(ret)) |
| 1807 | goto fail; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1808 | if ((val & 0x74) != 0x74) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1809 | pr_warn("expected 0x74, got 0x%x\n", (val & 0x74)); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1810 | #if 0 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1811 | /* FIXME - re-enable when we know this is right */ |
| 1812 | goto fail; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1813 | #endif |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1814 | } |
| 1815 | ret = lgdt3306a_read_reg(state, 0x0001, &val); |
| 1816 | if (lg_chkerr(ret)) |
| 1817 | goto fail; |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1818 | if ((val & 0xf6) != 0xc6) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1819 | pr_warn("expected 0xc6, got 0x%x\n", (val & 0xf6)); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1820 | #if 0 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1821 | /* FIXME - re-enable when we know this is right */ |
| 1822 | goto fail; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1823 | #endif |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1824 | } |
| 1825 | ret = lgdt3306a_read_reg(state, 0x0002, &val); |
| 1826 | if (lg_chkerr(ret)) |
| 1827 | goto fail; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1828 | if ((val & 0x73) != 0x03) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1829 | pr_warn("expected 0x03, got 0x%x\n", (val & 0x73)); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1830 | #if 0 |
Mauro Carvalho Chehab | 534f436 | 2014-10-28 12:35:18 -0200 | [diff] [blame] | 1831 | /* FIXME - re-enable when we know this is right */ |
| 1832 | goto fail; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 1833 | #endif |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | state->current_frequency = -1; |
| 1837 | state->current_modulation = -1; |
| 1838 | |
| 1839 | lgdt3306a_sleep(state); |
| 1840 | |
| 1841 | return &state->frontend; |
| 1842 | |
| 1843 | fail: |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 1844 | pr_warn("unable to detect LGDT3306A hardware\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1845 | kfree(state); |
| 1846 | return NULL; |
| 1847 | } |
Michael Ira Krufky | ebd9175 | 2014-08-03 15:05:59 -0300 | [diff] [blame] | 1848 | EXPORT_SYMBOL(lgdt3306a_attach); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1849 | |
| 1850 | #ifdef DBG_DUMP |
| 1851 | |
| 1852 | static const short regtab[] = { |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1853 | 0x0000, /* SOFTRSTB 1'b1 1'b1 1'b1 ADCPDB 1'b1 PLLPDB GBBPDB 11111111 */ |
| 1854 | 0x0001, /* 1'b1 1'b1 1'b0 1'b0 AUTORPTRS */ |
| 1855 | 0x0002, /* NI2CRPTEN 1'b0 1'b0 1'b0 SPECINVAUT */ |
| 1856 | 0x0003, /* AGCRFOUT */ |
| 1857 | 0x0004, /* ADCSEL1V ADCCNT ADCCNF ADCCNS ADCCLKPLL */ |
| 1858 | 0x0005, /* PLLINDIVSE */ |
| 1859 | 0x0006, /* PLLCTRL[7:0] 11100001 */ |
| 1860 | 0x0007, /* SYSINITWAITTIME[7:0] (msec) 00001000 */ |
| 1861 | 0x0008, /* STDOPMODE[7:0] 10000000 */ |
| 1862 | 0x0009, /* 1'b0 1'b0 1'b0 STDOPDETTMODE[2:0] STDOPDETCMODE[1:0] 00011110 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1863 | 0x000a, /* DAFTEN 1'b1 x x SCSYSLOCK */ |
| 1864 | 0x000b, /* SCSYSLOCKCHKTIME[7:0] (10msec) 01100100 */ |
| 1865 | 0x000d, /* x SAMPLING4 */ |
| 1866 | 0x000e, /* SAMFREQ[15:8] 00000000 */ |
| 1867 | 0x000f, /* SAMFREQ[7:0] 00000000 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1868 | 0x0010, /* IFFREQ[15:8] 01100000 */ |
| 1869 | 0x0011, /* IFFREQ[7:0] 00000000 */ |
| 1870 | 0x0012, /* AGCEN AGCREFMO */ |
| 1871 | 0x0013, /* AGCRFFIXB AGCIFFIXB AGCLOCKDETRNGSEL[1:0] 1'b1 1'b0 1'b0 1'b0 11101000 */ |
| 1872 | 0x0014, /* AGCFIXVALUE[7:0] 01111111 */ |
| 1873 | 0x0015, /* AGCREF[15:8] 00001010 */ |
| 1874 | 0x0016, /* AGCREF[7:0] 11100100 */ |
| 1875 | 0x0017, /* AGCDELAY[7:0] 00100000 */ |
| 1876 | 0x0018, /* AGCRFBW[3:0] AGCIFBW[3:0] 10001000 */ |
| 1877 | 0x0019, /* AGCUDOUTMODE[1:0] AGCUDCTRLLEN[1:0] AGCUDCTRL */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1878 | 0x001c, /* 1'b1 PFEN MFEN AICCVSYNC */ |
| 1879 | 0x001d, /* 1'b0 1'b1 1'b0 1'b1 AICCVSYNC */ |
| 1880 | 0x001e, /* AICCALPHA[3:0] 1'b1 1'b0 1'b1 1'b0 01111010 */ |
| 1881 | 0x001f, /* AICCDETTH[19:16] AICCOFFTH[19:16] 00000000 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1882 | 0x0020, /* AICCDETTH[15:8] 01111100 */ |
| 1883 | 0x0021, /* AICCDETTH[7:0] 00000000 */ |
| 1884 | 0x0022, /* AICCOFFTH[15:8] 00000101 */ |
| 1885 | 0x0023, /* AICCOFFTH[7:0] 11100000 */ |
| 1886 | 0x0024, /* AICCOPMODE3[1:0] AICCOPMODE2[1:0] AICCOPMODE1[1:0] AICCOPMODE0[1:0] 00000000 */ |
| 1887 | 0x0025, /* AICCFIXFREQ3[23:16] 00000000 */ |
| 1888 | 0x0026, /* AICCFIXFREQ3[15:8] 00000000 */ |
| 1889 | 0x0027, /* AICCFIXFREQ3[7:0] 00000000 */ |
| 1890 | 0x0028, /* AICCFIXFREQ2[23:16] 00000000 */ |
| 1891 | 0x0029, /* AICCFIXFREQ2[15:8] 00000000 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1892 | 0x002a, /* AICCFIXFREQ2[7:0] 00000000 */ |
| 1893 | 0x002b, /* AICCFIXFREQ1[23:16] 00000000 */ |
| 1894 | 0x002c, /* AICCFIXFREQ1[15:8] 00000000 */ |
| 1895 | 0x002d, /* AICCFIXFREQ1[7:0] 00000000 */ |
| 1896 | 0x002e, /* AICCFIXFREQ0[23:16] 00000000 */ |
| 1897 | 0x002f, /* AICCFIXFREQ0[15:8] 00000000 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1898 | 0x0030, /* AICCFIXFREQ0[7:0] 00000000 */ |
| 1899 | 0x0031, /* 1'b0 1'b1 1'b0 1'b0 x DAGC1STER */ |
| 1900 | 0x0032, /* DAGC1STEN DAGC1STER */ |
| 1901 | 0x0033, /* DAGC1STREF[15:8] 00001010 */ |
| 1902 | 0x0034, /* DAGC1STREF[7:0] 11100100 */ |
| 1903 | 0x0035, /* DAGC2NDE */ |
| 1904 | 0x0036, /* DAGC2NDREF[15:8] 00001010 */ |
| 1905 | 0x0037, /* DAGC2NDREF[7:0] 10000000 */ |
| 1906 | 0x0038, /* DAGC2NDLOCKDETRNGSEL[1:0] */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1907 | 0x003d, /* 1'b1 SAMGEARS */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1908 | 0x0040, /* SAMLFGMA */ |
| 1909 | 0x0041, /* SAMLFBWM */ |
| 1910 | 0x0044, /* 1'b1 CRGEARSHE */ |
| 1911 | 0x0045, /* CRLFGMAN */ |
| 1912 | 0x0046, /* CFLFBWMA */ |
| 1913 | 0x0047, /* CRLFGMAN */ |
| 1914 | 0x0048, /* x x x x CRLFGSTEP_VS[3:0] xxxx1001 */ |
| 1915 | 0x0049, /* CRLFBWMA */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1916 | 0x004a, /* CRLFBWMA */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1917 | 0x0050, /* 1'b0 1'b1 1'b1 1'b0 MSECALCDA */ |
| 1918 | 0x0070, /* TPOUTEN TPIFEN TPCLKOUTE */ |
| 1919 | 0x0071, /* TPSENB TPSSOPBITE */ |
| 1920 | 0x0073, /* TP47HINS x x CHBERINT PERMODE[1:0] PERINT[1:0] 1xx11100 */ |
| 1921 | 0x0075, /* x x x x x IQSWAPCTRL[2:0] xxxxx000 */ |
| 1922 | 0x0076, /* NBERCON NBERST NBERPOL NBERWSYN */ |
| 1923 | 0x0077, /* x NBERLOSTTH[2:0] NBERACQTH[3:0] x0000000 */ |
| 1924 | 0x0078, /* NBERPOLY[31:24] 00000000 */ |
| 1925 | 0x0079, /* NBERPOLY[23:16] 00000000 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1926 | 0x007a, /* NBERPOLY[15:8] 00000000 */ |
| 1927 | 0x007b, /* NBERPOLY[7:0] 00000000 */ |
| 1928 | 0x007c, /* NBERPED[31:24] 00000000 */ |
| 1929 | 0x007d, /* NBERPED[23:16] 00000000 */ |
| 1930 | 0x007e, /* NBERPED[15:8] 00000000 */ |
| 1931 | 0x007f, /* NBERPED[7:0] 00000000 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1932 | 0x0080, /* x AGCLOCK DAGCLOCK SYSLOCK x x NEVERLOCK[1:0] */ |
| 1933 | 0x0085, /* SPECINVST */ |
| 1934 | 0x0088, /* SYSLOCKTIME[15:8] */ |
| 1935 | 0x0089, /* SYSLOCKTIME[7:0] */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1936 | 0x008c, /* FECLOCKTIME[15:8] */ |
| 1937 | 0x008d, /* FECLOCKTIME[7:0] */ |
| 1938 | 0x008e, /* AGCACCOUT[15:8] */ |
| 1939 | 0x008f, /* AGCACCOUT[7:0] */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1940 | 0x0090, /* AICCREJSTATUS[3:0] AICCREJBUSY[3:0] */ |
| 1941 | 0x0091, /* AICCVSYNC */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1942 | 0x009c, /* CARRFREQOFFSET[15:8] */ |
| 1943 | 0x009d, /* CARRFREQOFFSET[7:0] */ |
| 1944 | 0x00a1, /* SAMFREQOFFSET[23:16] */ |
| 1945 | 0x00a2, /* SAMFREQOFFSET[15:8] */ |
| 1946 | 0x00a3, /* SAMFREQOFFSET[7:0] */ |
| 1947 | 0x00a6, /* SYNCLOCK SYNCLOCKH */ |
Michael Ira Krufky | 6da7ac9 | 2014-10-25 11:05:05 -0300 | [diff] [blame] | 1948 | #if 0 /* covered elsewhere */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1949 | 0x00e8, /* CONSTPWR[15:8] */ |
| 1950 | 0x00e9, /* CONSTPWR[7:0] */ |
| 1951 | 0x00ea, /* BMSE[15:8] */ |
| 1952 | 0x00eb, /* BMSE[7:0] */ |
| 1953 | 0x00ec, /* MSE[15:8] */ |
| 1954 | 0x00ed, /* MSE[7:0] */ |
| 1955 | 0x00ee, /* CONSTI[7:0] */ |
| 1956 | 0x00ef, /* CONSTQ[7:0] */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 1957 | #endif |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1958 | 0x00f4, /* TPIFTPERRCNT[7:0] */ |
| 1959 | 0x00f5, /* TPCORREC */ |
| 1960 | 0x00f6, /* VBBER[15:8] */ |
| 1961 | 0x00f7, /* VBBER[7:0] */ |
| 1962 | 0x00f8, /* VABER[15:8] */ |
| 1963 | 0x00f9, /* VABER[7:0] */ |
| 1964 | 0x00fa, /* TPERRCNT[7:0] */ |
| 1965 | 0x00fb, /* NBERLOCK x x x x x x x */ |
| 1966 | 0x00fc, /* NBERVALUE[31:24] */ |
| 1967 | 0x00fd, /* NBERVALUE[23:16] */ |
| 1968 | 0x00fe, /* NBERVALUE[15:8] */ |
| 1969 | 0x00ff, /* NBERVALUE[7:0] */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1970 | 0x1000, /* 1'b0 WODAGCOU */ |
| 1971 | 0x1005, /* x x 1'b1 1'b1 x SRD_Q_QM */ |
| 1972 | 0x1009, /* SRDWAITTIME[7:0] (10msec) 00100011 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1973 | 0x100a, /* SRDWAITTIME_CQS[7:0] (msec) 01100100 */ |
| 1974 | 0x101a, /* x 1'b1 1'b0 1'b0 x QMDQAMMODE[2:0] x100x010 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1975 | 0x1036, /* 1'b0 1'b1 1'b0 1'b0 SAMGSEND_CQS[3:0] 01001110 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1976 | 0x103c, /* SAMGSAUTOSTL_V[3:0] SAMGSAUTOEDL_V[3:0] 01000110 */ |
| 1977 | 0x103d, /* 1'b1 1'b1 SAMCNORMBP_V[1:0] 1'b0 1'b0 SAMMODESEL_V[1:0] 11100001 */ |
| 1978 | 0x103f, /* SAMZTEDSE */ |
| 1979 | 0x105d, /* EQSTATUSE */ |
| 1980 | 0x105f, /* x PMAPG2_V[2:0] x DMAPG2_V[2:0] x001x011 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1981 | 0x1060, /* 1'b1 EQSTATUSE */ |
| 1982 | 0x1061, /* CRMAPBWSTL_V[3:0] CRMAPBWEDL_V[3:0] 00000100 */ |
| 1983 | 0x1065, /* 1'b0 x CRMODE_V[1:0] 1'b1 x 1'b1 x 0x111x1x */ |
| 1984 | 0x1066, /* 1'b0 1'b0 1'b1 1'b0 1'b1 PNBOOSTSE */ |
| 1985 | 0x1068, /* CREPHNGAIN2_V[3:0] CREPHNPBW_V[3:0] 10010001 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1986 | 0x106e, /* x x x x x CREPHNEN_ */ |
| 1987 | 0x106f, /* CREPHNTH_V[7:0] 00010101 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 1988 | 0x1072, /* CRSWEEPN */ |
| 1989 | 0x1073, /* CRPGAIN_V[3:0] x x 1'b1 1'b1 1001xx11 */ |
| 1990 | 0x1074, /* CRPBW_V[3:0] x x 1'b1 1'b1 0001xx11 */ |
| 1991 | 0x1080, /* DAFTSTATUS[1:0] x x x x x x */ |
| 1992 | 0x1081, /* SRDSTATUS[1:0] x x x x x SRDLOCK */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1993 | 0x10a9, /* EQSTATUS_CQS[1:0] x x x x x x */ |
| 1994 | 0x10b7, /* EQSTATUS_V[1:0] x x x x x x */ |
Michael Ira Krufky | 6da7ac9 | 2014-10-25 11:05:05 -0300 | [diff] [blame] | 1995 | #if 0 /* SMART_ANT */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 1996 | 0x1f00, /* MODEDETE */ |
| 1997 | 0x1f01, /* x x x x x x x SFNRST xxxxxxx0 */ |
| 1998 | 0x1f03, /* NUMOFANT[7:0] 10000000 */ |
| 1999 | 0x1f04, /* x SELMASK[6:0] x0000000 */ |
| 2000 | 0x1f05, /* x SETMASK[6:0] x0000000 */ |
| 2001 | 0x1f06, /* x TXDATA[6:0] x0000000 */ |
| 2002 | 0x1f07, /* x CHNUMBER[6:0] x0000000 */ |
| 2003 | 0x1f09, /* AGCTIME[23:16] 10011000 */ |
| 2004 | 0x1f0a, /* AGCTIME[15:8] 10010110 */ |
| 2005 | 0x1f0b, /* AGCTIME[7:0] 10000000 */ |
| 2006 | 0x1f0c, /* ANTTIME[31:24] 00000000 */ |
| 2007 | 0x1f0d, /* ANTTIME[23:16] 00000011 */ |
| 2008 | 0x1f0e, /* ANTTIME[15:8] 10010000 */ |
| 2009 | 0x1f0f, /* ANTTIME[7:0] 10010000 */ |
| 2010 | 0x1f11, /* SYNCTIME[23:16] 10011000 */ |
| 2011 | 0x1f12, /* SYNCTIME[15:8] 10010110 */ |
| 2012 | 0x1f13, /* SYNCTIME[7:0] 10000000 */ |
| 2013 | 0x1f14, /* SNRTIME[31:24] 00000001 */ |
| 2014 | 0x1f15, /* SNRTIME[23:16] 01111101 */ |
| 2015 | 0x1f16, /* SNRTIME[15:8] 01111000 */ |
| 2016 | 0x1f17, /* SNRTIME[7:0] 01000000 */ |
| 2017 | 0x1f19, /* FECTIME[23:16] 00000000 */ |
| 2018 | 0x1f1a, /* FECTIME[15:8] 01110010 */ |
| 2019 | 0x1f1b, /* FECTIME[7:0] 01110000 */ |
| 2020 | 0x1f1d, /* FECTHD[7:0] 00000011 */ |
| 2021 | 0x1f1f, /* SNRTHD[23:16] 00001000 */ |
| 2022 | 0x1f20, /* SNRTHD[15:8] 01111111 */ |
| 2023 | 0x1f21, /* SNRTHD[7:0] 10000101 */ |
| 2024 | 0x1f80, /* IRQFLG x x SFSDRFLG MODEBFLG SAVEFLG SCANFLG TRACKFLG */ |
| 2025 | 0x1f81, /* x SYNCCON SNRCON FECCON x STDBUSY SYNCRST AGCFZCO */ |
| 2026 | 0x1f82, /* x x x SCANOPCD[4:0] */ |
| 2027 | 0x1f83, /* x x x x MAINOPCD[3:0] */ |
| 2028 | 0x1f84, /* x x RXDATA[13:8] */ |
| 2029 | 0x1f85, /* RXDATA[7:0] */ |
| 2030 | 0x1f86, /* x x SDTDATA[13:8] */ |
| 2031 | 0x1f87, /* SDTDATA[7:0] */ |
| 2032 | 0x1f89, /* ANTSNR[23:16] */ |
| 2033 | 0x1f8a, /* ANTSNR[15:8] */ |
| 2034 | 0x1f8b, /* ANTSNR[7:0] */ |
| 2035 | 0x1f8c, /* x x x x ANTFEC[13:8] */ |
| 2036 | 0x1f8d, /* ANTFEC[7:0] */ |
| 2037 | 0x1f8e, /* MAXCNT[7:0] */ |
| 2038 | 0x1f8f, /* SCANCNT[7:0] */ |
| 2039 | 0x1f91, /* MAXPW[23:16] */ |
| 2040 | 0x1f92, /* MAXPW[15:8] */ |
| 2041 | 0x1f93, /* MAXPW[7:0] */ |
| 2042 | 0x1f95, /* CURPWMSE[23:16] */ |
| 2043 | 0x1f96, /* CURPWMSE[15:8] */ |
| 2044 | 0x1f97, /* CURPWMSE[7:0] */ |
Michael Ira Krufky | 6da7ac9 | 2014-10-25 11:05:05 -0300 | [diff] [blame] | 2045 | #endif /* SMART_ANT */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2046 | 0x211f, /* 1'b1 1'b1 1'b1 CIRQEN x x 1'b0 1'b0 1111xx00 */ |
| 2047 | 0x212a, /* EQAUTOST */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 2048 | 0x2122, /* CHFAST[7:0] 01100000 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2049 | 0x212b, /* FFFSTEP_V[3:0] x FBFSTEP_V[2:0] 0001x001 */ |
| 2050 | 0x212c, /* PHDEROTBWSEL[3:0] 1'b1 1'b1 1'b1 1'b0 10001110 */ |
| 2051 | 0x212d, /* 1'b1 1'b1 1'b1 1'b1 x x TPIFLOCKS */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 2052 | 0x2135, /* DYNTRACKFDEQ[3:0] x 1'b0 1'b0 1'b0 1010x000 */ |
| 2053 | 0x2141, /* TRMODE[1:0] 1'b1 1'b1 1'b0 1'b1 1'b1 1'b1 01110111 */ |
| 2054 | 0x2162, /* AICCCTRLE */ |
| 2055 | 0x2173, /* PHNCNFCNT[7:0] 00000100 */ |
| 2056 | 0x2179, /* 1'b0 1'b0 1'b0 1'b1 x BADSINGLEDYNTRACKFBF[2:0] 0001x001 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2057 | 0x217a, /* 1'b0 1'b0 1'b0 1'b1 x BADSLOWSINGLEDYNTRACKFBF[2:0] 0001x001 */ |
| 2058 | 0x217e, /* CNFCNTTPIF[7:0] 00001000 */ |
| 2059 | 0x217f, /* TPERRCNTTPIF[7:0] 00000001 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 2060 | 0x2180, /* x x x x x x FBDLYCIR[9:8] */ |
| 2061 | 0x2181, /* FBDLYCIR[7:0] */ |
| 2062 | 0x2185, /* MAXPWRMAIN[7:0] */ |
| 2063 | 0x2191, /* NCOMBDET x x x x x x x */ |
| 2064 | 0x2199, /* x MAINSTRON */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2065 | 0x219a, /* FFFEQSTEPOUT_V[3:0] FBFSTEPOUT_V[2:0] */ |
| 2066 | 0x21a1, /* x x SNRREF[5:0] */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 2067 | 0x2845, /* 1'b0 1'b1 x x FFFSTEP_CQS[1:0] FFFCENTERTAP[1:0] 01xx1110 */ |
| 2068 | 0x2846, /* 1'b0 x 1'b0 1'b1 FBFSTEP_CQS[1:0] 1'b1 1'b0 0x011110 */ |
| 2069 | 0x2847, /* ENNOSIGDE */ |
| 2070 | 0x2849, /* 1'b1 1'b1 NOUSENOSI */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2071 | 0x284a, /* EQINITWAITTIME[7:0] 01100100 */ |
Michael Ira Krufky | cb4671c | 2014-10-25 11:12:25 -0300 | [diff] [blame] | 2072 | 0x3000, /* 1'b1 1'b1 1'b1 x x x 1'b0 RPTRSTM */ |
| 2073 | 0x3001, /* RPTRSTWAITTIME[7:0] (100msec) 00110010 */ |
| 2074 | 0x3031, /* FRAMELOC */ |
| 2075 | 0x3032, /* 1'b1 1'b0 1'b0 1'b0 x x FRAMELOCKMODE_CQS[1:0] 1000xx11 */ |
Mauro Carvalho Chehab | 4937ba9 | 2014-10-28 10:50:36 -0200 | [diff] [blame] | 2076 | 0x30a9, /* VDLOCK_Q FRAMELOCK */ |
| 2077 | 0x30aa, /* MPEGLOCK */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2078 | }; |
| 2079 | |
Michael Ira Krufky | 34a5a2f | 2014-10-25 11:26:15 -0300 | [diff] [blame] | 2080 | #define numDumpRegs (sizeof(regtab)/sizeof(regtab[0])) |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2081 | static u8 regval1[numDumpRegs] = {0, }; |
| 2082 | static u8 regval2[numDumpRegs] = {0, }; |
| 2083 | |
| 2084 | static void lgdt3306a_DumpAllRegs(struct lgdt3306a_state *state) |
| 2085 | { |
| 2086 | memset(regval2, 0xff, sizeof(regval2)); |
| 2087 | lgdt3306a_DumpRegs(state); |
| 2088 | } |
| 2089 | |
| 2090 | static void lgdt3306a_DumpRegs(struct lgdt3306a_state *state) |
| 2091 | { |
| 2092 | int i; |
| 2093 | int sav_debug = debug; |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 2094 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2095 | if ((debug & DBG_DUMP) == 0) |
| 2096 | return; |
Michael Ira Krufky | 831a911 | 2014-10-25 11:20:57 -0300 | [diff] [blame] | 2097 | debug &= ~DBG_REG; /* suppress DBG_REG during reg dump */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2098 | |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 2099 | lg_debug("\n"); |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2100 | |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 2101 | for (i = 0; i < numDumpRegs; i++) { |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2102 | lgdt3306a_read_reg(state, regtab[i], ®val1[i]); |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 2103 | if (regval1[i] != regval2[i]) { |
Mauro Carvalho Chehab | 097117c | 2014-10-28 11:35:16 -0200 | [diff] [blame] | 2104 | lg_debug(" %04X = %02X\n", regtab[i], regval1[i]); |
Mauro Carvalho Chehab | 16afc67 | 2015-04-28 18:31:21 -0300 | [diff] [blame] | 2105 | regval2[i] = regval1[i]; |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2106 | } |
| 2107 | } |
| 2108 | debug = sav_debug; |
| 2109 | } |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 2110 | #endif /* DBG_DUMP */ |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2111 | |
| 2112 | |
| 2113 | |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2114 | static struct dvb_frontend_ops lgdt3306a_ops = { |
| 2115 | .delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B }, |
| 2116 | .info = { |
| 2117 | .name = "LG Electronics LGDT3306A VSB/QAM Frontend", |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2118 | .frequency_min = 54000000, |
Michael Ira Krufky | 8e8cd34 | 2014-07-27 19:24:24 -0300 | [diff] [blame] | 2119 | .frequency_max = 858000000, |
Fred Richter | b63b36f | 2014-03-24 19:56:00 -0300 | [diff] [blame] | 2120 | .frequency_stepsize = 62500, |
| 2121 | .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB |
| 2122 | }, |
| 2123 | .i2c_gate_ctrl = lgdt3306a_i2c_gate_ctrl, |
| 2124 | .init = lgdt3306a_init, |
| 2125 | .sleep = lgdt3306a_fe_sleep, |
| 2126 | /* if this is set, it overrides the default swzigzag */ |
| 2127 | .tune = lgdt3306a_tune, |
| 2128 | .set_frontend = lgdt3306a_set_parameters, |
| 2129 | .get_frontend = lgdt3306a_get_frontend, |
| 2130 | .get_frontend_algo = lgdt3306a_get_frontend_algo, |
| 2131 | .get_tune_settings = lgdt3306a_get_tune_settings, |
| 2132 | .read_status = lgdt3306a_read_status, |
| 2133 | .read_ber = lgdt3306a_read_ber, |
| 2134 | .read_signal_strength = lgdt3306a_read_signal_strength, |
| 2135 | .read_snr = lgdt3306a_read_snr, |
| 2136 | .read_ucblocks = lgdt3306a_read_ucblocks, |
| 2137 | .release = lgdt3306a_release, |
| 2138 | .ts_bus_ctrl = lgdt3306a_ts_bus_ctrl, |
| 2139 | .search = lgdt3306a_search, |
| 2140 | }; |
| 2141 | |
| 2142 | MODULE_DESCRIPTION("LG Electronics LGDT3306A ATSC/QAM-B Demodulator Driver"); |
| 2143 | MODULE_AUTHOR("Fred Richter <frichter@hauppauge.com>"); |
| 2144 | MODULE_LICENSE("GPL"); |
| 2145 | MODULE_VERSION("0.2"); |