Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | Conexant 22702 DVB OFDM demodulator driver |
| 3 | |
| 4 | based on: |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 5 | Alps TDMB7 DVB OFDM demodulator driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | |
| 7 | Copyright (C) 2001-2002 Convergence Integrated Media GmbH |
| 8 | Holger Waechtler <holger@convergence.de> |
| 9 | |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 10 | Copyright (C) 2004 Steven Toth <stoth@linuxtv.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 2 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | |
| 26 | */ |
| 27 | |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/delay.h> |
| 34 | #include "dvb_frontend.h" |
| 35 | #include "cx22702.h" |
| 36 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | struct cx22702_state { |
| 38 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 39 | struct i2c_adapter *i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | /* configuration settings */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 42 | const struct cx22702_config *config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | struct dvb_frontend frontend; |
| 45 | |
| 46 | /* previous uncorrected block counter */ |
| 47 | u8 prevUCBlocks; |
| 48 | }; |
| 49 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 50 | static int debug; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 51 | module_param(debug, int, 0644); |
| 52 | MODULE_PARM_DESC(debug, "Enable verbose debug messages"); |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #define dprintk if (debug) printk |
| 55 | |
| 56 | /* Register values to initialise the demod */ |
Jean Delvare | bdc6fad | 2010-09-10 10:35:12 -0300 | [diff] [blame] | 57 | static const u8 init_tab[] = { |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 58 | 0x00, 0x00, /* Stop acquisition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | 0x0B, 0x06, |
| 60 | 0x09, 0x01, |
| 61 | 0x0D, 0x41, |
| 62 | 0x16, 0x32, |
| 63 | 0x20, 0x0A, |
| 64 | 0x21, 0x17, |
| 65 | 0x24, 0x3e, |
| 66 | 0x26, 0xff, |
| 67 | 0x27, 0x10, |
| 68 | 0x28, 0x00, |
| 69 | 0x29, 0x00, |
| 70 | 0x2a, 0x10, |
| 71 | 0x2b, 0x00, |
| 72 | 0x2c, 0x10, |
| 73 | 0x2d, 0x00, |
| 74 | 0x48, 0xd4, |
| 75 | 0x49, 0x56, |
| 76 | 0x6b, 0x1e, |
| 77 | 0xc8, 0x02, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | 0xf9, 0x00, |
| 79 | 0xfa, 0x00, |
| 80 | 0xfb, 0x00, |
| 81 | 0xfc, 0x00, |
| 82 | 0xfd, 0x00, |
| 83 | }; |
| 84 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 85 | static int cx22702_writereg(struct cx22702_state *state, u8 reg, u8 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | { |
| 87 | int ret; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 88 | u8 buf[] = { reg, data }; |
| 89 | struct i2c_msg msg = { |
| 90 | .addr = state->config->demod_address, .flags = 0, |
| 91 | .buf = buf, .len = 2 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | ret = i2c_transfer(state->i2c, &msg, 1); |
| 94 | |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 95 | if (unlikely(ret != 1)) { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 96 | printk(KERN_ERR |
| 97 | "%s: error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 98 | __func__, reg, data, ret); |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 99 | return -1; |
| 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 102 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 105 | static u8 cx22702_readreg(struct cx22702_state *state, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | { |
| 107 | int ret; |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 108 | u8 data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 110 | struct i2c_msg msg[] = { |
| 111 | { .addr = state->config->demod_address, .flags = 0, |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 112 | .buf = ®, .len = 1 }, |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 113 | { .addr = state->config->demod_address, .flags = I2C_M_RD, |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 114 | .buf = &data, .len = 1 } }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | ret = i2c_transfer(state->i2c, msg, 2); |
| 117 | |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 118 | if (unlikely(ret != 2)) { |
| 119 | printk(KERN_ERR "%s: error (reg == 0x%02x, ret == %i)\n", |
| 120 | __func__, reg, ret); |
| 121 | return 0; |
| 122 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
Jean Delvare | 2476410 | 2010-09-10 14:03:07 -0300 | [diff] [blame] | 124 | return data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 127 | static int cx22702_set_inversion(struct cx22702_state *state, int inversion) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | { |
| 129 | u8 val; |
| 130 | |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 131 | val = cx22702_readreg(state, 0x0C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | switch (inversion) { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 133 | case INVERSION_AUTO: |
| 134 | return -EOPNOTSUPP; |
| 135 | case INVERSION_ON: |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 136 | val |= 0x01; |
| 137 | break; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 138 | case INVERSION_OFF: |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 139 | val &= 0xfe; |
| 140 | break; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 141 | default: |
| 142 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 144 | return cx22702_writereg(state, 0x0C, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Retrieve the demod settings */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 148 | static int cx22702_get_tps(struct cx22702_state *state, |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 149 | struct dtv_frontend_properties *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | { |
| 151 | u8 val; |
| 152 | |
| 153 | /* Make sure the TPS regs are valid */ |
| 154 | if (!(cx22702_readreg(state, 0x0A) & 0x20)) |
| 155 | return -EAGAIN; |
| 156 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 157 | val = cx22702_readreg(state, 0x01); |
| 158 | switch ((val & 0x18) >> 3) { |
| 159 | case 0: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 160 | p->modulation = QPSK; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 161 | break; |
| 162 | case 1: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 163 | p->modulation = QAM_16; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 164 | break; |
| 165 | case 2: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 166 | p->modulation = QAM_64; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 167 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 169 | switch (val & 0x07) { |
| 170 | case 0: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 171 | p->hierarchy = HIERARCHY_NONE; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 172 | break; |
| 173 | case 1: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 174 | p->hierarchy = HIERARCHY_1; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 175 | break; |
| 176 | case 2: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 177 | p->hierarchy = HIERARCHY_2; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 178 | break; |
| 179 | case 3: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 180 | p->hierarchy = HIERARCHY_4; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 181 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 185 | val = cx22702_readreg(state, 0x02); |
| 186 | switch ((val & 0x38) >> 3) { |
| 187 | case 0: |
| 188 | p->code_rate_HP = FEC_1_2; |
| 189 | break; |
| 190 | case 1: |
| 191 | p->code_rate_HP = FEC_2_3; |
| 192 | break; |
| 193 | case 2: |
| 194 | p->code_rate_HP = FEC_3_4; |
| 195 | break; |
| 196 | case 3: |
| 197 | p->code_rate_HP = FEC_5_6; |
| 198 | break; |
| 199 | case 4: |
| 200 | p->code_rate_HP = FEC_7_8; |
| 201 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 203 | switch (val & 0x07) { |
| 204 | case 0: |
| 205 | p->code_rate_LP = FEC_1_2; |
| 206 | break; |
| 207 | case 1: |
| 208 | p->code_rate_LP = FEC_2_3; |
| 209 | break; |
| 210 | case 2: |
| 211 | p->code_rate_LP = FEC_3_4; |
| 212 | break; |
| 213 | case 3: |
| 214 | p->code_rate_LP = FEC_5_6; |
| 215 | break; |
| 216 | case 4: |
| 217 | p->code_rate_LP = FEC_7_8; |
| 218 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 221 | val = cx22702_readreg(state, 0x03); |
| 222 | switch ((val & 0x0c) >> 2) { |
| 223 | case 0: |
| 224 | p->guard_interval = GUARD_INTERVAL_1_32; |
| 225 | break; |
| 226 | case 1: |
| 227 | p->guard_interval = GUARD_INTERVAL_1_16; |
| 228 | break; |
| 229 | case 2: |
| 230 | p->guard_interval = GUARD_INTERVAL_1_8; |
| 231 | break; |
| 232 | case 3: |
| 233 | p->guard_interval = GUARD_INTERVAL_1_4; |
| 234 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 236 | switch (val & 0x03) { |
| 237 | case 0: |
| 238 | p->transmission_mode = TRANSMISSION_MODE_2K; |
| 239 | break; |
| 240 | case 1: |
| 241 | p->transmission_mode = TRANSMISSION_MODE_8K; |
| 242 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 248 | static int cx22702_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 249 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 250 | struct cx22702_state *state = fe->demodulator_priv; |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 251 | u8 val; |
| 252 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 253 | dprintk("%s(%d)\n", __func__, enable); |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 254 | val = cx22702_readreg(state, 0x0D); |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 255 | if (enable) |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 256 | val &= 0xfe; |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 257 | else |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 258 | val |= 0x01; |
| 259 | return cx22702_writereg(state, 0x0D, val); |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | /* Talk to the demod, set the FEC, GUARD, QAM settings etc */ |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 263 | static int cx22702_set_tps(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 265 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | u8 val; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 267 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 269 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 270 | fe->ops.tuner_ops.set_params(fe); |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 271 | if (fe->ops.i2c_gate_ctrl) |
| 272 | fe->ops.i2c_gate_ctrl(fe, 0); |
Gerd Knorr | 9990d74 | 2005-05-01 08:59:20 -0700 | [diff] [blame] | 273 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
| 275 | /* set inversion */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 276 | cx22702_set_inversion(state, p->inversion); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* set bandwidth */ |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 279 | val = cx22702_readreg(state, 0x0C) & 0xcf; |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 280 | switch (p->bandwidth_hz) { |
| 281 | case 6000000: |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 282 | val |= 0x20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | break; |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 284 | case 7000000: |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 285 | val |= 0x10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | break; |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 287 | case 8000000: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | break; |
| 289 | default: |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 290 | dprintk("%s: invalid bandwidth\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return -EINVAL; |
| 292 | } |
Jean Delvare | 27f84ac | 2010-09-10 10:33:42 -0300 | [diff] [blame] | 293 | cx22702_writereg(state, 0x0C, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 295 | p->code_rate_LP = FEC_AUTO; /* temp hack as manual not working */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | |
| 297 | /* use auto configuration? */ |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 298 | if ((p->hierarchy == HIERARCHY_AUTO) || |
| 299 | (p->modulation == QAM_AUTO) || |
| 300 | (p->code_rate_HP == FEC_AUTO) || |
| 301 | (p->code_rate_LP == FEC_AUTO) || |
| 302 | (p->guard_interval == GUARD_INTERVAL_AUTO) || |
| 303 | (p->transmission_mode == TRANSMISSION_MODE_AUTO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | /* TPS Source - use hardware driven values */ |
| 306 | cx22702_writereg(state, 0x06, 0x10); |
| 307 | cx22702_writereg(state, 0x07, 0x9); |
| 308 | cx22702_writereg(state, 0x08, 0xC1); |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 309 | cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B) |
| 310 | & 0xfc); |
| 311 | cx22702_writereg(state, 0x0C, |
| 312 | (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 313 | cx22702_writereg(state, 0x00, 0x01); /* Begin acquisition */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 314 | dprintk("%s: Autodetecting\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | return 0; |
| 316 | } |
| 317 | |
| 318 | /* manually programmed values */ |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 319 | switch (p->modulation) { /* mask 0x18 */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 320 | case QPSK: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 321 | val = 0x00; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 322 | break; |
| 323 | case QAM_16: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 324 | val = 0x08; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 325 | break; |
| 326 | case QAM_64: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 327 | val = 0x10; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 328 | break; |
| 329 | default: |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 330 | dprintk("%s: invalid modulation\n", __func__); |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 331 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 333 | switch (p->hierarchy) { /* mask 0x07 */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 334 | case HIERARCHY_NONE: |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 335 | break; |
| 336 | case HIERARCHY_1: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 337 | val |= 0x01; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 338 | break; |
| 339 | case HIERARCHY_2: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 340 | val |= 0x02; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 341 | break; |
| 342 | case HIERARCHY_4: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 343 | val |= 0x03; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 344 | break; |
| 345 | default: |
| 346 | dprintk("%s: invalid hierarchy\n", __func__); |
| 347 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 349 | cx22702_writereg(state, 0x06, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 351 | switch (p->code_rate_HP) { /* mask 0x38 */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 352 | case FEC_NONE: |
| 353 | case FEC_1_2: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 354 | val = 0x00; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 355 | break; |
| 356 | case FEC_2_3: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 357 | val = 0x08; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 358 | break; |
| 359 | case FEC_3_4: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 360 | val = 0x10; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 361 | break; |
| 362 | case FEC_5_6: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 363 | val = 0x18; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 364 | break; |
| 365 | case FEC_7_8: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 366 | val = 0x20; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 367 | break; |
| 368 | default: |
| 369 | dprintk("%s: invalid code_rate_HP\n", __func__); |
| 370 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | } |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 372 | switch (p->code_rate_LP) { /* mask 0x07 */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 373 | case FEC_NONE: |
| 374 | case FEC_1_2: |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 375 | break; |
| 376 | case FEC_2_3: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 377 | val |= 0x01; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 378 | break; |
| 379 | case FEC_3_4: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 380 | val |= 0x02; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 381 | break; |
| 382 | case FEC_5_6: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 383 | val |= 0x03; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 384 | break; |
| 385 | case FEC_7_8: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 386 | val |= 0x04; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 387 | break; |
| 388 | default: |
| 389 | dprintk("%s: invalid code_rate_LP\n", __func__); |
| 390 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 392 | cx22702_writereg(state, 0x07, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 394 | switch (p->guard_interval) { /* mask 0x0c */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 395 | case GUARD_INTERVAL_1_32: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 396 | val = 0x00; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 397 | break; |
| 398 | case GUARD_INTERVAL_1_16: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 399 | val = 0x04; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 400 | break; |
| 401 | case GUARD_INTERVAL_1_8: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 402 | val = 0x08; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 403 | break; |
| 404 | case GUARD_INTERVAL_1_4: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 405 | val = 0x0c; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 406 | break; |
| 407 | default: |
| 408 | dprintk("%s: invalid guard_interval\n", __func__); |
| 409 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 411 | switch (p->transmission_mode) { /* mask 0x03 */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 412 | case TRANSMISSION_MODE_2K: |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 413 | break; |
| 414 | case TRANSMISSION_MODE_8K: |
Jean Delvare | f89ca6f | 2010-09-10 10:36:37 -0300 | [diff] [blame] | 415 | val |= 0x1; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 416 | break; |
| 417 | default: |
| 418 | dprintk("%s: invalid transmission_mode\n", __func__); |
| 419 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | cx22702_writereg(state, 0x08, val); |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 422 | cx22702_writereg(state, 0x0B, |
| 423 | (cx22702_readreg(state, 0x0B) & 0xfc) | 0x02); |
| 424 | cx22702_writereg(state, 0x0C, |
| 425 | (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 427 | /* Begin channel acquisition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | cx22702_writereg(state, 0x00, 0x01); |
| 429 | |
| 430 | return 0; |
| 431 | } |
| 432 | |
| 433 | /* Reset the demod hardware and reset all of the configuration registers |
| 434 | to a default state. */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 435 | static int cx22702_init(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
| 437 | int i; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 438 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 440 | cx22702_writereg(state, 0x00, 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | msleep(10); |
| 443 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 444 | for (i = 0; i < ARRAY_SIZE(init_tab); i += 2) |
| 445 | cx22702_writereg(state, init_tab[i], init_tab[i + 1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 447 | cx22702_writereg(state, 0xf8, (state->config->output_mode << 1) |
| 448 | & 0x02); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Steven Toth | 611900c | 2006-01-09 15:25:12 -0200 | [diff] [blame] | 450 | cx22702_i2c_gate_ctrl(fe, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 455 | static int cx22702_read_status(struct dvb_frontend *fe, fe_status_t *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 457 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | u8 reg0A; |
| 459 | u8 reg23; |
| 460 | |
| 461 | *status = 0; |
| 462 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 463 | reg0A = cx22702_readreg(state, 0x0A); |
| 464 | reg23 = cx22702_readreg(state, 0x23); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 466 | dprintk("%s: status demod=0x%02x agc=0x%02x\n" |
| 467 | , __func__, reg0A, reg23); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 469 | if (reg0A & 0x10) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | *status |= FE_HAS_LOCK; |
| 471 | *status |= FE_HAS_VITERBI; |
| 472 | *status |= FE_HAS_SYNC; |
| 473 | } |
| 474 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 475 | if (reg0A & 0x20) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | *status |= FE_HAS_CARRIER; |
| 477 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 478 | if (reg23 < 0xf0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | *status |= FE_HAS_SIGNAL; |
| 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 484 | static int cx22702_read_ber(struct dvb_frontend *fe, u32 *ber) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 486 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 488 | if (cx22702_readreg(state, 0xE4) & 0x02) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | /* Realtime statistics */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 490 | *ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7 |
| 491 | | (cx22702_readreg(state, 0xDF) & 0x7F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | } else { |
| 493 | /* Averagtine statistics */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 494 | *ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7 |
| 495 | | cx22702_readreg(state, 0xDF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 501 | static int cx22702_read_signal_strength(struct dvb_frontend *fe, |
| 502 | u16 *signal_strength) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 504 | struct cx22702_state *state = fe->demodulator_priv; |
Jean Delvare | 06302ff | 2012-02-12 15:03:03 -0300 | [diff] [blame] | 505 | u8 reg23; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Jean Delvare | 06302ff | 2012-02-12 15:03:03 -0300 | [diff] [blame] | 507 | /* |
| 508 | * Experience suggests that the strength signal register works as |
| 509 | * follows: |
| 510 | * - In the absence of signal, value is 0xff. |
| 511 | * - In the presence of a weak signal, bit 7 is set, not sure what |
| 512 | * the lower 7 bits mean. |
| 513 | * - In the presence of a strong signal, the register holds a 7-bit |
| 514 | * value (bit 7 is cleared), with greater values standing for |
| 515 | * weaker signals. |
| 516 | */ |
| 517 | reg23 = cx22702_readreg(state, 0x23); |
| 518 | if (reg23 & 0x80) { |
| 519 | *signal_strength = 0; |
| 520 | } else { |
| 521 | reg23 = ~reg23 & 0x7f; |
| 522 | /* Scale to 16 bit */ |
| 523 | *signal_strength = (reg23 << 9) | (reg23 << 2) | (reg23 >> 5); |
| 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 529 | static int cx22702_read_snr(struct dvb_frontend *fe, u16 *snr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 531 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
Jean Delvare | 5b9a6f3 | 2010-09-10 10:32:21 -0300 | [diff] [blame] | 533 | u16 rs_ber; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 534 | if (cx22702_readreg(state, 0xE4) & 0x02) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | /* Realtime statistics */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 536 | rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 7 |
| 537 | | (cx22702_readreg(state, 0xDF) & 0x7F); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } else { |
| 539 | /* Averagine statistics */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 540 | rs_ber = (cx22702_readreg(state, 0xDE) & 0x7F) << 8 |
| 541 | | cx22702_readreg(state, 0xDF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | *snr = ~rs_ber; |
| 544 | |
| 545 | return 0; |
| 546 | } |
| 547 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 548 | static int cx22702_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 550 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | |
| 552 | u8 _ucblocks; |
| 553 | |
| 554 | /* RS Uncorrectable Packet Count then reset */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 555 | _ucblocks = cx22702_readreg(state, 0xE3); |
Patrick Boettcher | f46dbb0 | 2005-07-07 17:57:44 -0700 | [diff] [blame] | 556 | if (state->prevUCBlocks < _ucblocks) |
| 557 | *ucblocks = (_ucblocks - state->prevUCBlocks); |
| 558 | else |
| 559 | *ucblocks = state->prevUCBlocks - _ucblocks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | state->prevUCBlocks = _ucblocks; |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 565 | static int cx22702_get_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 567 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 568 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 570 | u8 reg0C = cx22702_readreg(state, 0x0C); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 572 | c->inversion = reg0C & 0x1 ? INVERSION_ON : INVERSION_OFF; |
| 573 | return cx22702_get_tps(state, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 576 | static int cx22702_get_tune_settings(struct dvb_frontend *fe, |
| 577 | struct dvb_frontend_tune_settings *tune) |
Patrick Boettcher | f46dbb0 | 2005-07-07 17:57:44 -0700 | [diff] [blame] | 578 | { |
| 579 | tune->min_delay_ms = 1000; |
| 580 | return 0; |
| 581 | } |
| 582 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 583 | static void cx22702_release(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 585 | struct cx22702_state *state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | kfree(state); |
| 587 | } |
| 588 | |
Jean Delvare | bdc6fad | 2010-09-10 10:35:12 -0300 | [diff] [blame] | 589 | static const struct dvb_frontend_ops cx22702_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 591 | struct dvb_frontend *cx22702_attach(const struct cx22702_config *config, |
| 592 | struct i2c_adapter *i2c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | { |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 594 | struct cx22702_state *state = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
| 596 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 597 | state = kzalloc(sizeof(struct cx22702_state), GFP_KERNEL); |
Patrick Boettcher | f46dbb0 | 2005-07-07 17:57:44 -0700 | [diff] [blame] | 598 | if (state == NULL) |
| 599 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | |
| 601 | /* setup the state */ |
| 602 | state->config = config; |
| 603 | state->i2c = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | |
| 605 | /* check if the demod is there */ |
Patrick Boettcher | f46dbb0 | 2005-07-07 17:57:44 -0700 | [diff] [blame] | 606 | if (cx22702_readreg(state, 0x1f) != 0x3) |
| 607 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
| 609 | /* create dvb_frontend */ |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 610 | memcpy(&state->frontend.ops, &cx22702_ops, |
| 611 | sizeof(struct dvb_frontend_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | state->frontend.demodulator_priv = state; |
| 613 | return &state->frontend; |
| 614 | |
| 615 | error: |
| 616 | kfree(state); |
| 617 | return NULL; |
| 618 | } |
Steven Toth | 4e3599a | 2008-10-16 20:23:45 -0300 | [diff] [blame] | 619 | EXPORT_SYMBOL(cx22702_attach); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
Jean Delvare | bdc6fad | 2010-09-10 10:35:12 -0300 | [diff] [blame] | 621 | static const struct dvb_frontend_ops cx22702_ops = { |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 622 | .delsys = { SYS_DVBT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | .info = { |
| 624 | .name = "Conexant CX22702 DVB-T", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | .frequency_min = 177000000, |
| 626 | .frequency_max = 858000000, |
| 627 | .frequency_stepsize = 166666, |
| 628 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 629 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 630 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO | |
| 631 | FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO | |
| 632 | FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER |
| 633 | }, |
| 634 | |
| 635 | .release = cx22702_release, |
| 636 | |
| 637 | .init = cx22702_init, |
Andrew de Quincey | 0244422 | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 638 | .i2c_gate_ctrl = cx22702_i2c_gate_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
Mauro Carvalho Chehab | 19289a2 | 2011-12-22 16:40:49 -0300 | [diff] [blame] | 640 | .set_frontend = cx22702_set_tps, |
| 641 | .get_frontend = cx22702_get_frontend, |
Patrick Boettcher | f46dbb0 | 2005-07-07 17:57:44 -0700 | [diff] [blame] | 642 | .get_tune_settings = cx22702_get_tune_settings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | .read_status = cx22702_read_status, |
| 645 | .read_ber = cx22702_read_ber, |
| 646 | .read_signal_strength = cx22702_read_signal_strength, |
| 647 | .read_snr = cx22702_read_snr, |
| 648 | .read_ucblocks = cx22702_read_ucblocks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | }; |
| 650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | MODULE_DESCRIPTION("Conexant CX22702 DVB-T Demodulator driver"); |
| 652 | MODULE_AUTHOR("Steven Toth"); |
| 653 | MODULE_LICENSE("GPL"); |