Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | NxtWave Communications - NXT6000 demodulator driver |
| 3 | |
| 4 | Copyright (C) 2002-2003 Florian Schirmer <jolt@tuxbox.org> |
| 5 | Copyright (C) 2003 Paul Andreassen <paul@andreassen.com.au> |
| 6 | |
| 7 | This program is free software; you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation; either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program; if not, write to the Free Software |
| 19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 22 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/string.h> |
| 28 | #include <linux/slab.h> |
| 29 | |
| 30 | #include "dvb_frontend.h" |
| 31 | #include "nxt6000_priv.h" |
| 32 | #include "nxt6000.h" |
| 33 | |
| 34 | |
| 35 | |
| 36 | struct nxt6000_state { |
| 37 | struct i2c_adapter* i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | /* configuration settings */ |
| 39 | const struct nxt6000_config* config; |
| 40 | struct dvb_frontend frontend; |
| 41 | }; |
| 42 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 43 | static int debug; |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 44 | #define dprintk(fmt, arg...) do { \ |
| 45 | if (debug) \ |
| 46 | printk(KERN_DEBUG pr_fmt("%s: " fmt), \ |
| 47 | __func__, ##arg); \ |
| 48 | } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | static int nxt6000_writereg(struct nxt6000_state* state, u8 reg, u8 data) |
| 51 | { |
| 52 | u8 buf[] = { reg, data }; |
| 53 | struct i2c_msg msg = {.addr = state->config->demod_address,.flags = 0,.buf = buf,.len = 2 }; |
| 54 | int ret; |
| 55 | |
| 56 | if ((ret = i2c_transfer(state->i2c, &msg, 1)) != 1) |
| 57 | dprintk("nxt6000: nxt6000_write error (reg: 0x%02X, data: 0x%02X, ret: %d)\n", reg, data, ret); |
| 58 | |
Mauro Carvalho Chehab | 7464aa5 | 2011-07-06 12:41:21 -0300 | [diff] [blame] | 59 | return (ret != 1) ? -EIO : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | static u8 nxt6000_readreg(struct nxt6000_state* state, u8 reg) |
| 63 | { |
| 64 | int ret; |
| 65 | u8 b0[] = { reg }; |
| 66 | u8 b1[] = { 0 }; |
| 67 | struct i2c_msg msgs[] = { |
| 68 | {.addr = state->config->demod_address,.flags = 0,.buf = b0,.len = 1}, |
| 69 | {.addr = state->config->demod_address,.flags = I2C_M_RD,.buf = b1,.len = 1} |
| 70 | }; |
| 71 | |
| 72 | ret = i2c_transfer(state->i2c, msgs, 2); |
| 73 | |
| 74 | if (ret != 2) |
| 75 | dprintk("nxt6000: nxt6000_read error (reg: 0x%02X, ret: %d)\n", reg, ret); |
| 76 | |
| 77 | return b1[0]; |
| 78 | } |
| 79 | |
| 80 | static void nxt6000_reset(struct nxt6000_state* state) |
| 81 | { |
| 82 | u8 val; |
| 83 | |
| 84 | val = nxt6000_readreg(state, OFDM_COR_CTL); |
| 85 | |
| 86 | nxt6000_writereg(state, OFDM_COR_CTL, val & ~COREACT); |
| 87 | nxt6000_writereg(state, OFDM_COR_CTL, val | COREACT); |
| 88 | } |
| 89 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 90 | static int nxt6000_set_bandwidth(struct nxt6000_state *state, u32 bandwidth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | u16 nominal_rate; |
| 93 | int result; |
| 94 | |
| 95 | switch (bandwidth) { |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 96 | case 6000000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | nominal_rate = 0x55B7; |
| 98 | break; |
| 99 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 100 | case 7000000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | nominal_rate = 0x6400; |
| 102 | break; |
| 103 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 104 | case 8000000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | nominal_rate = 0x7249; |
| 106 | break; |
| 107 | |
| 108 | default: |
| 109 | return -EINVAL; |
| 110 | } |
| 111 | |
| 112 | if ((result = nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_1, nominal_rate & 0xFF)) < 0) |
| 113 | return result; |
| 114 | |
| 115 | return nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_2, (nominal_rate >> 8) & 0xFF); |
| 116 | } |
| 117 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 118 | static int nxt6000_set_guard_interval(struct nxt6000_state *state, |
| 119 | enum fe_guard_interval guard_interval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | switch (guard_interval) { |
| 122 | |
| 123 | case GUARD_INTERVAL_1_32: |
| 124 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, 0x00 | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x03)); |
| 125 | |
| 126 | case GUARD_INTERVAL_1_16: |
| 127 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, 0x01 | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x03)); |
| 128 | |
| 129 | case GUARD_INTERVAL_AUTO: |
| 130 | case GUARD_INTERVAL_1_8: |
| 131 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, 0x02 | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x03)); |
| 132 | |
| 133 | case GUARD_INTERVAL_1_4: |
| 134 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, 0x03 | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x03)); |
| 135 | |
| 136 | default: |
| 137 | return -EINVAL; |
| 138 | } |
| 139 | } |
| 140 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 141 | static int nxt6000_set_inversion(struct nxt6000_state *state, |
| 142 | enum fe_spectral_inversion inversion) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { |
| 144 | switch (inversion) { |
| 145 | |
| 146 | case INVERSION_OFF: |
| 147 | return nxt6000_writereg(state, OFDM_ITB_CTL, 0x00); |
| 148 | |
| 149 | case INVERSION_ON: |
| 150 | return nxt6000_writereg(state, OFDM_ITB_CTL, ITBINV); |
| 151 | |
| 152 | default: |
| 153 | return -EINVAL; |
| 154 | |
| 155 | } |
| 156 | } |
| 157 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 158 | static int |
| 159 | nxt6000_set_transmission_mode(struct nxt6000_state *state, |
| 160 | enum fe_transmit_mode transmission_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
| 162 | int result; |
| 163 | |
| 164 | switch (transmission_mode) { |
| 165 | |
| 166 | case TRANSMISSION_MODE_2K: |
| 167 | if ((result = nxt6000_writereg(state, EN_DMD_RACQ, 0x00 | (nxt6000_readreg(state, EN_DMD_RACQ) & ~0x03))) < 0) |
| 168 | return result; |
| 169 | |
| 170 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, (0x00 << 2) | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x04)); |
| 171 | |
| 172 | case TRANSMISSION_MODE_8K: |
| 173 | case TRANSMISSION_MODE_AUTO: |
| 174 | if ((result = nxt6000_writereg(state, EN_DMD_RACQ, 0x02 | (nxt6000_readreg(state, EN_DMD_RACQ) & ~0x03))) < 0) |
| 175 | return result; |
| 176 | |
| 177 | return nxt6000_writereg(state, OFDM_COR_MODEGUARD, (0x01 << 2) | (nxt6000_readreg(state, OFDM_COR_MODEGUARD) & ~0x04)); |
| 178 | |
| 179 | default: |
| 180 | return -EINVAL; |
| 181 | |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | static void nxt6000_setup(struct dvb_frontend* fe) |
| 186 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 187 | struct nxt6000_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
| 189 | nxt6000_writereg(state, RS_COR_SYNC_PARAM, SYNC_PARAM); |
| 190 | nxt6000_writereg(state, BER_CTRL, /*(1 << 2) | */ (0x01 << 1) | 0x01); |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 191 | nxt6000_writereg(state, VIT_BERTIME_2, 0x00); // BER Timer = 0x000200 * 256 = 131072 bits |
| 192 | nxt6000_writereg(state, VIT_BERTIME_1, 0x02); // |
| 193 | nxt6000_writereg(state, VIT_BERTIME_0, 0x00); // |
| 194 | nxt6000_writereg(state, VIT_COR_INTEN, 0x98); // Enable BER interrupts |
| 195 | nxt6000_writereg(state, VIT_COR_CTL, 0x82); // Enable BER measurement |
| 196 | nxt6000_writereg(state, VIT_COR_CTL, VIT_COR_RESYNC | 0x02 ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | nxt6000_writereg(state, OFDM_COR_CTL, (0x01 << 5) | (nxt6000_readreg(state, OFDM_COR_CTL) & 0x0F)); |
| 198 | nxt6000_writereg(state, OFDM_COR_MODEGUARD, FORCEMODE8K | 0x02); |
| 199 | nxt6000_writereg(state, OFDM_AGC_CTL, AGCLAST | INITIAL_AGC_BW); |
| 200 | nxt6000_writereg(state, OFDM_ITB_FREQ_1, 0x06); |
| 201 | nxt6000_writereg(state, OFDM_ITB_FREQ_2, 0x31); |
| 202 | nxt6000_writereg(state, OFDM_CAS_CTL, (0x01 << 7) | (0x02 << 3) | 0x04); |
| 203 | nxt6000_writereg(state, CAS_FREQ, 0xBB); /* CHECKME */ |
| 204 | nxt6000_writereg(state, OFDM_SYR_CTL, 1 << 2); |
| 205 | nxt6000_writereg(state, OFDM_PPM_CTL_1, PPM256); |
| 206 | nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_1, 0x49); |
| 207 | nxt6000_writereg(state, OFDM_TRL_NOMINALRATE_2, 0x72); |
| 208 | nxt6000_writereg(state, ANALOG_CONTROL_0, 1 << 5); |
| 209 | nxt6000_writereg(state, EN_DMD_RACQ, (1 << 7) | (3 << 4) | 2); |
| 210 | nxt6000_writereg(state, DIAG_CONFIG, TB_SET); |
| 211 | |
| 212 | if (state->config->clock_inversion) |
| 213 | nxt6000_writereg(state, SUB_DIAG_MODE_SEL, CLKINVERSION); |
| 214 | else |
| 215 | nxt6000_writereg(state, SUB_DIAG_MODE_SEL, 0); |
| 216 | |
| 217 | nxt6000_writereg(state, TS_FORMAT, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void nxt6000_dump_status(struct nxt6000_state *state) |
| 221 | { |
| 222 | u8 val; |
| 223 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 224 | #if 0 |
| 225 | pr_info("RS_COR_STAT: 0x%02X\n", |
| 226 | nxt6000_readreg(fe, RS_COR_STAT)); |
| 227 | pr_info("VIT_SYNC_STATUS: 0x%02X\n", |
| 228 | nxt6000_readreg(fe, VIT_SYNC_STATUS)); |
| 229 | pr_info("OFDM_COR_STAT: 0x%02X\n", |
| 230 | nxt6000_readreg(fe, OFDM_COR_STAT)); |
| 231 | pr_info("OFDM_SYR_STAT: 0x%02X\n", |
| 232 | nxt6000_readreg(fe, OFDM_SYR_STAT)); |
| 233 | pr_info("OFDM_TPS_RCVD_1: 0x%02X\n", |
| 234 | nxt6000_readreg(fe, OFDM_TPS_RCVD_1)); |
| 235 | pr_info("OFDM_TPS_RCVD_2: 0x%02X\n", |
| 236 | nxt6000_readreg(fe, OFDM_TPS_RCVD_2)); |
| 237 | pr_info("OFDM_TPS_RCVD_3: 0x%02X\n", |
| 238 | nxt6000_readreg(fe, OFDM_TPS_RCVD_3)); |
| 239 | pr_info("OFDM_TPS_RCVD_4: 0x%02X\n", |
| 240 | nxt6000_readreg(fe, OFDM_TPS_RCVD_4)); |
| 241 | pr_info("OFDM_TPS_RESERVED_1: 0x%02X\n", |
| 242 | nxt6000_readreg(fe, OFDM_TPS_RESERVED_1)); |
| 243 | pr_info("OFDM_TPS_RESERVED_2: 0x%02X\n", |
| 244 | nxt6000_readreg(fe, OFDM_TPS_RESERVED_2)); |
| 245 | #endif |
| 246 | pr_info("NXT6000 status:"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | val = nxt6000_readreg(state, RS_COR_STAT); |
| 249 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 250 | pr_cont(" DATA DESCR LOCK: %d,", val & 0x01); |
| 251 | pr_cont(" DATA SYNC LOCK: %d,", (val >> 1) & 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
| 253 | val = nxt6000_readreg(state, VIT_SYNC_STATUS); |
| 254 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 255 | pr_cont(" VITERBI LOCK: %d,", (val >> 7) & 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | switch ((val >> 4) & 0x07) { |
| 258 | |
| 259 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 260 | pr_cont(" VITERBI CODERATE: 1/2,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 264 | pr_cont(" VITERBI CODERATE: 2/3,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | break; |
| 266 | |
| 267 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 268 | pr_cont(" VITERBI CODERATE: 3/4,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | break; |
| 270 | |
| 271 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 272 | pr_cont(" VITERBI CODERATE: 5/6,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | break; |
| 274 | |
| 275 | case 0x04: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 276 | pr_cont(" VITERBI CODERATE: 7/8,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | default: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 280 | pr_cont(" VITERBI CODERATE: Reserved,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
| 282 | } |
| 283 | |
| 284 | val = nxt6000_readreg(state, OFDM_COR_STAT); |
| 285 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 286 | pr_cont(" CHCTrack: %d,", (val >> 7) & 0x01); |
| 287 | pr_cont(" TPSLock: %d,", (val >> 6) & 0x01); |
| 288 | pr_cont(" SYRLock: %d,", (val >> 5) & 0x01); |
| 289 | pr_cont(" AGCLock: %d,", (val >> 4) & 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | switch (val & 0x0F) { |
| 292 | |
| 293 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 294 | pr_cont(" CoreState: IDLE,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | break; |
| 296 | |
| 297 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 298 | pr_cont(" CoreState: WAIT_AGC,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | break; |
| 300 | |
| 301 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 302 | pr_cont(" CoreState: WAIT_SYR,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | break; |
| 304 | |
| 305 | case 0x04: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 306 | pr_cont(" CoreState: WAIT_PPM,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | break; |
| 308 | |
| 309 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 310 | pr_cont(" CoreState: WAIT_TRL,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | break; |
| 312 | |
| 313 | case 0x05: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 314 | pr_cont(" CoreState: WAIT_TPS,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | break; |
| 316 | |
| 317 | case 0x06: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 318 | pr_cont(" CoreState: MONITOR_TPS,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | break; |
| 320 | |
| 321 | default: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 322 | pr_cont(" CoreState: Reserved,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | } |
| 325 | |
| 326 | val = nxt6000_readreg(state, OFDM_SYR_STAT); |
| 327 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 328 | pr_cont(" SYRLock: %d,", (val >> 4) & 0x01); |
| 329 | pr_cont(" SYRMode: %s,", (val >> 2) & 0x01 ? "8K" : "2K"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | |
| 331 | switch ((val >> 4) & 0x03) { |
| 332 | |
| 333 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 334 | pr_cont(" SYRGuard: 1/32,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | break; |
| 336 | |
| 337 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 338 | pr_cont(" SYRGuard: 1/16,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | break; |
| 340 | |
| 341 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 342 | pr_cont(" SYRGuard: 1/8,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | break; |
| 344 | |
| 345 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 346 | pr_cont(" SYRGuard: 1/4,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | break; |
| 348 | } |
| 349 | |
| 350 | val = nxt6000_readreg(state, OFDM_TPS_RCVD_3); |
| 351 | |
| 352 | switch ((val >> 4) & 0x07) { |
| 353 | |
| 354 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 355 | pr_cont(" TPSLP: 1/2,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | break; |
| 357 | |
| 358 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 359 | pr_cont(" TPSLP: 2/3,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | break; |
| 361 | |
| 362 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 363 | pr_cont(" TPSLP: 3/4,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | break; |
| 365 | |
| 366 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 367 | pr_cont(" TPSLP: 5/6,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | break; |
| 369 | |
| 370 | case 0x04: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 371 | pr_cont(" TPSLP: 7/8,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | break; |
| 373 | |
| 374 | default: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 375 | pr_cont(" TPSLP: Reserved,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | |
| 377 | } |
| 378 | |
| 379 | switch (val & 0x07) { |
| 380 | |
| 381 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 382 | pr_cont(" TPSHP: 1/2,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | break; |
| 384 | |
| 385 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 386 | pr_cont(" TPSHP: 2/3,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | break; |
| 388 | |
| 389 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 390 | pr_cont(" TPSHP: 3/4,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | break; |
| 392 | |
| 393 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 394 | pr_cont(" TPSHP: 5/6,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | break; |
| 396 | |
| 397 | case 0x04: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 398 | pr_cont(" TPSHP: 7/8,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | break; |
| 400 | |
| 401 | default: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 402 | pr_cont(" TPSHP: Reserved,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
| 404 | } |
| 405 | |
| 406 | val = nxt6000_readreg(state, OFDM_TPS_RCVD_4); |
| 407 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 408 | pr_cont(" TPSMode: %s,", val & 0x01 ? "8K" : "2K"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | switch ((val >> 4) & 0x03) { |
| 411 | |
| 412 | case 0x00: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 413 | pr_cont(" TPSGuard: 1/32,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | break; |
| 415 | |
| 416 | case 0x01: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 417 | pr_cont(" TPSGuard: 1/16,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | break; |
| 419 | |
| 420 | case 0x02: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 421 | pr_cont(" TPSGuard: 1/8,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | break; |
| 423 | |
| 424 | case 0x03: |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 425 | pr_cont(" TPSGuard: 1/4,"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | break; |
| 427 | |
| 428 | } |
| 429 | |
| 430 | /* Strange magic required to gain access to RF_AGC_STATUS */ |
| 431 | nxt6000_readreg(state, RF_AGC_VAL_1); |
| 432 | val = nxt6000_readreg(state, RF_AGC_STATUS); |
| 433 | val = nxt6000_readreg(state, RF_AGC_STATUS); |
| 434 | |
Mauro Carvalho Chehab | cc5ad2b | 2016-10-13 15:37:40 -0300 | [diff] [blame] | 435 | pr_cont(" RF AGC LOCK: %d,", (val >> 4) & 0x01); |
| 436 | pr_cont("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 439 | static int nxt6000_read_status(struct dvb_frontend *fe, enum fe_status *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
| 441 | u8 core_status; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 442 | struct nxt6000_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | *status = 0; |
| 445 | |
| 446 | core_status = nxt6000_readreg(state, OFDM_COR_STAT); |
| 447 | |
| 448 | if (core_status & AGCLOCKED) |
| 449 | *status |= FE_HAS_SIGNAL; |
| 450 | |
| 451 | if (nxt6000_readreg(state, OFDM_SYR_STAT) & GI14_SYR_LOCK) |
| 452 | *status |= FE_HAS_CARRIER; |
| 453 | |
| 454 | if (nxt6000_readreg(state, VIT_SYNC_STATUS) & VITINSYNC) |
| 455 | *status |= FE_HAS_VITERBI; |
| 456 | |
| 457 | if (nxt6000_readreg(state, RS_COR_STAT) & RSCORESTATUS) |
| 458 | *status |= FE_HAS_SYNC; |
| 459 | |
| 460 | if ((core_status & TPSLOCKED) && (*status == (FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))) |
| 461 | *status |= FE_HAS_LOCK; |
| 462 | |
| 463 | if (debug) |
| 464 | nxt6000_dump_status(state); |
| 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static int nxt6000_init(struct dvb_frontend* fe) |
| 470 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 471 | struct nxt6000_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
| 473 | nxt6000_reset(state); |
| 474 | nxt6000_setup(fe); |
| 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 479 | static int nxt6000_set_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 481 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 482 | struct nxt6000_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | int result; |
| 484 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 485 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 486 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 487 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 605ee41 | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 488 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 490 | result = nxt6000_set_bandwidth(state, p->bandwidth_hz); |
| 491 | if (result < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | return result; |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 493 | |
| 494 | result = nxt6000_set_guard_interval(state, p->guard_interval); |
| 495 | if (result < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | return result; |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 497 | |
| 498 | result = nxt6000_set_transmission_mode(state, p->transmission_mode); |
| 499 | if (result < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | return result; |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 501 | |
| 502 | result = nxt6000_set_inversion(state, p->inversion); |
| 503 | if (result < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return result; |
| 505 | |
Svante Olofsson | 115eea4 | 2005-09-09 13:02:48 -0700 | [diff] [blame] | 506 | msleep(500); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | static void nxt6000_release(struct dvb_frontend* fe) |
| 511 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 512 | struct nxt6000_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | kfree(state); |
| 514 | } |
| 515 | |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 516 | static int nxt6000_read_snr(struct dvb_frontend* fe, u16* snr) |
| 517 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 518 | struct nxt6000_state* state = fe->demodulator_priv; |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 519 | |
| 520 | *snr = nxt6000_readreg( state, OFDM_CHC_SNR) / 8; |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
| 525 | static int nxt6000_read_ber(struct dvb_frontend* fe, u32* ber) |
| 526 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 527 | struct nxt6000_state* state = fe->demodulator_priv; |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 528 | |
| 529 | nxt6000_writereg( state, VIT_COR_INTSTAT, 0x18 ); |
| 530 | |
| 531 | *ber = (nxt6000_readreg( state, VIT_BER_1 ) << 8 ) | |
| 532 | nxt6000_readreg( state, VIT_BER_0 ); |
| 533 | |
| 534 | nxt6000_writereg( state, VIT_COR_INTSTAT, 0x18); // Clear BER Done interrupts |
| 535 | |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static int nxt6000_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) |
| 540 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 541 | struct nxt6000_state* state = fe->demodulator_priv; |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 542 | |
| 543 | *signal_strength = (short) (511 - |
| 544 | (nxt6000_readreg(state, AGC_GAIN_1) + |
| 545 | ((nxt6000_readreg(state, AGC_GAIN_2) & 0x03) << 8))); |
| 546 | |
| 547 | return 0; |
| 548 | } |
| 549 | |
Svante Olofsson | 115eea4 | 2005-09-09 13:02:48 -0700 | [diff] [blame] | 550 | static int nxt6000_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) |
| 551 | { |
| 552 | tune->min_delay_ms = 500; |
| 553 | return 0; |
| 554 | } |
| 555 | |
Andrew de Quincey | 605ee41 | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 556 | static int nxt6000_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) |
| 557 | { |
| 558 | struct nxt6000_state* state = fe->demodulator_priv; |
| 559 | |
| 560 | if (enable) { |
| 561 | return nxt6000_writereg(state, ENABLE_TUNER_IIC, 0x01); |
| 562 | } else { |
| 563 | return nxt6000_writereg(state, ENABLE_TUNER_IIC, 0x00); |
| 564 | } |
| 565 | } |
| 566 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 567 | static const struct dvb_frontend_ops nxt6000_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, |
| 570 | struct i2c_adapter* i2c) |
| 571 | { |
| 572 | struct nxt6000_state* state = NULL; |
| 573 | |
| 574 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 575 | state = kzalloc(sizeof(struct nxt6000_state), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | if (state == NULL) goto error; |
| 577 | |
| 578 | /* setup the state */ |
| 579 | state->config = config; |
| 580 | state->i2c = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | /* check if the demod is there */ |
| 583 | if (nxt6000_readreg(state, OFDM_MSC_REV) != NXT6000ASICDEVICE) goto error; |
| 584 | |
| 585 | /* create dvb_frontend */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 586 | memcpy(&state->frontend.ops, &nxt6000_ops, sizeof(struct dvb_frontend_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | state->frontend.demodulator_priv = state; |
| 588 | return &state->frontend; |
| 589 | |
| 590 | error: |
| 591 | kfree(state); |
| 592 | return NULL; |
| 593 | } |
| 594 | |
Max Kellermann | bd336e6 | 2016-08-09 18:32:21 -0300 | [diff] [blame] | 595 | static const struct dvb_frontend_ops nxt6000_ops = { |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 596 | .delsys = { SYS_DVBT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | .info = { |
| 598 | .name = "NxtWave NXT6000 DVB-T", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | .frequency_min = 0, |
| 600 | .frequency_max = 863250000, |
| 601 | .frequency_stepsize = 62500, |
| 602 | /*.frequency_tolerance = *//* FIXME: 12% of SR */ |
| 603 | .symbol_rate_min = 0, /* FIXME */ |
| 604 | .symbol_rate_max = 9360000, /* FIXME */ |
| 605 | .symbol_rate_tolerance = 4000, |
| 606 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
Michael Krufky | 50c25ff | 2006-01-09 15:25:34 -0200 | [diff] [blame] | 607 | FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | |
| 608 | FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO | |
| 609 | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | |
| 610 | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | |
| 611 | FE_CAN_HIERARCHY_AUTO, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | }, |
| 613 | |
| 614 | .release = nxt6000_release, |
| 615 | |
| 616 | .init = nxt6000_init, |
Andrew de Quincey | 605ee41 | 2006-04-18 17:47:11 -0300 | [diff] [blame] | 617 | .i2c_gate_ctrl = nxt6000_i2c_gate_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Svante Olofsson | 115eea4 | 2005-09-09 13:02:48 -0700 | [diff] [blame] | 619 | .get_tune_settings = nxt6000_fe_get_tune_settings, |
| 620 | |
Mauro Carvalho Chehab | 80b5b74 | 2011-12-26 12:26:34 -0300 | [diff] [blame] | 621 | .set_frontend = nxt6000_set_frontend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | |
| 623 | .read_status = nxt6000_read_status, |
Johannes Stezenbach | 3a4a571 | 2005-05-16 21:54:29 -0700 | [diff] [blame] | 624 | .read_ber = nxt6000_read_ber, |
| 625 | .read_signal_strength = nxt6000_read_signal_strength, |
| 626 | .read_snr = nxt6000_read_snr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | }; |
| 628 | |
| 629 | module_param(debug, int, 0644); |
| 630 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 631 | |
| 632 | MODULE_DESCRIPTION("NxtWave NXT6000 DVB-T demodulator driver"); |
| 633 | MODULE_AUTHOR("Florian Schirmer"); |
| 634 | MODULE_LICENSE("GPL"); |
| 635 | |
| 636 | EXPORT_SYMBOL(nxt6000_attach); |