Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | Conexant cx22700 DVB OFDM demodulator driver |
| 3 | |
| 4 | Copyright (C) 2001-2002 Convergence Integrated Media GmbH |
| 5 | Holger Waechtler <holger@convergence.de> |
| 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 | */ |
| 22 | |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include "dvb_frontend.h" |
| 29 | #include "cx22700.h" |
| 30 | |
| 31 | |
| 32 | struct cx22700_state { |
| 33 | |
| 34 | struct i2c_adapter* i2c; |
| 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | const struct cx22700_config* config; |
| 37 | |
| 38 | struct dvb_frontend frontend; |
| 39 | }; |
| 40 | |
| 41 | |
| 42 | static int debug; |
| 43 | #define dprintk(args...) \ |
| 44 | do { \ |
| 45 | if (debug) printk(KERN_DEBUG "cx22700: " args); \ |
| 46 | } while (0) |
| 47 | |
| 48 | static u8 init_tab [] = { |
| 49 | 0x04, 0x10, |
| 50 | 0x05, 0x09, |
| 51 | 0x06, 0x00, |
| 52 | 0x08, 0x04, |
| 53 | 0x09, 0x00, |
| 54 | 0x0a, 0x01, |
| 55 | 0x15, 0x40, |
| 56 | 0x16, 0x10, |
| 57 | 0x17, 0x87, |
| 58 | 0x18, 0x17, |
| 59 | 0x1a, 0x10, |
| 60 | 0x25, 0x04, |
| 61 | 0x2e, 0x00, |
| 62 | 0x39, 0x00, |
| 63 | 0x3a, 0x04, |
| 64 | 0x45, 0x08, |
| 65 | 0x46, 0x02, |
| 66 | 0x47, 0x05, |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | static int cx22700_writereg (struct cx22700_state* state, u8 reg, u8 data) |
| 71 | { |
| 72 | int ret; |
| 73 | u8 buf [] = { reg, data }; |
| 74 | struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; |
| 75 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 76 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | ret = i2c_transfer (state->i2c, &msg, 1); |
| 79 | |
| 80 | if (ret != 1) |
| 81 | printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 82 | __func__, reg, data, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | return (ret != 1) ? -1 : 0; |
| 85 | } |
| 86 | |
| 87 | static int cx22700_readreg (struct cx22700_state* state, u8 reg) |
| 88 | { |
| 89 | int ret; |
| 90 | u8 b0 [] = { reg }; |
| 91 | u8 b1 [] = { 0 }; |
| 92 | struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, |
| 93 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } }; |
| 94 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 95 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | |
| 97 | ret = i2c_transfer (state->i2c, msg, 2); |
| 98 | |
| 99 | if (ret != 2) return -EIO; |
| 100 | |
| 101 | return b1[0]; |
| 102 | } |
| 103 | |
| 104 | static int cx22700_set_inversion (struct cx22700_state* state, int inversion) |
| 105 | { |
| 106 | u8 val; |
| 107 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 108 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
| 110 | switch (inversion) { |
| 111 | case INVERSION_AUTO: |
| 112 | return -EOPNOTSUPP; |
| 113 | case INVERSION_ON: |
| 114 | val = cx22700_readreg (state, 0x09); |
| 115 | return cx22700_writereg (state, 0x09, val | 0x01); |
| 116 | case INVERSION_OFF: |
| 117 | val = cx22700_readreg (state, 0x09); |
| 118 | return cx22700_writereg (state, 0x09, val & 0xfe); |
| 119 | default: |
| 120 | return -EINVAL; |
| 121 | } |
| 122 | } |
| 123 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 124 | static int cx22700_set_tps(struct cx22700_state *state, |
| 125 | struct dtv_frontend_properties *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
| 127 | static const u8 qam_tab [4] = { 0, 1, 0, 2 }; |
| 128 | static const u8 fec_tab [6] = { 0, 1, 2, 0, 3, 4 }; |
| 129 | u8 val; |
| 130 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 131 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | if (p->code_rate_HP < FEC_1_2 || p->code_rate_HP > FEC_7_8) |
| 134 | return -EINVAL; |
| 135 | |
| 136 | if (p->code_rate_LP < FEC_1_2 || p->code_rate_LP > FEC_7_8) |
Eric Sesterhenn | 91a0791 | 2006-06-30 11:51:11 -0300 | [diff] [blame] | 137 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | if (p->code_rate_HP == FEC_4_5 || p->code_rate_LP == FEC_4_5) |
| 140 | return -EINVAL; |
| 141 | |
Mauro Carvalho Chehab | 830e4b5 | 2012-10-27 16:14:01 -0300 | [diff] [blame] | 142 | if ((int)p->guard_interval < GUARD_INTERVAL_1_32 || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | p->guard_interval > GUARD_INTERVAL_1_4) |
| 144 | return -EINVAL; |
| 145 | |
| 146 | if (p->transmission_mode != TRANSMISSION_MODE_2K && |
| 147 | p->transmission_mode != TRANSMISSION_MODE_8K) |
| 148 | return -EINVAL; |
| 149 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 150 | if (p->modulation != QPSK && |
| 151 | p->modulation != QAM_16 && |
| 152 | p->modulation != QAM_64) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | return -EINVAL; |
| 154 | |
Mauro Carvalho Chehab | 830e4b5 | 2012-10-27 16:14:01 -0300 | [diff] [blame] | 155 | if ((int)p->hierarchy < HIERARCHY_NONE || |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 156 | p->hierarchy > HIERARCHY_4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | return -EINVAL; |
| 158 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 159 | if (p->bandwidth_hz > 8000000 || p->bandwidth_hz < 6000000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | return -EINVAL; |
| 161 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 162 | if (p->bandwidth_hz == 7000000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | cx22700_writereg (state, 0x09, cx22700_readreg (state, 0x09 | 0x10)); |
| 164 | else |
| 165 | cx22700_writereg (state, 0x09, cx22700_readreg (state, 0x09 & ~0x10)); |
| 166 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 167 | val = qam_tab[p->modulation - QPSK]; |
| 168 | val |= p->hierarchy - HIERARCHY_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | cx22700_writereg (state, 0x04, val); |
| 171 | |
Mauro Carvalho Chehab | 667c952 | 2014-11-05 09:42:22 -0200 | [diff] [blame] | 172 | if (p->code_rate_HP - FEC_1_2 >= sizeof(fec_tab) || |
| 173 | p->code_rate_LP - FEC_1_2 >= sizeof(fec_tab)) |
| 174 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | val = fec_tab[p->code_rate_HP - FEC_1_2] << 3; |
| 176 | val |= fec_tab[p->code_rate_LP - FEC_1_2]; |
| 177 | |
| 178 | cx22700_writereg (state, 0x05, val); |
| 179 | |
| 180 | val = (p->guard_interval - GUARD_INTERVAL_1_32) << 2; |
| 181 | val |= p->transmission_mode - TRANSMISSION_MODE_2K; |
| 182 | |
| 183 | cx22700_writereg (state, 0x06, val); |
| 184 | |
| 185 | cx22700_writereg (state, 0x08, 0x04 | 0x02); /* use user tps parameters */ |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 186 | cx22700_writereg (state, 0x08, 0x04); /* restart acquisition */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 191 | static int cx22700_get_tps(struct cx22700_state *state, |
| 192 | struct dtv_frontend_properties *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | { |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 194 | static const enum fe_modulation qam_tab[3] = { QPSK, QAM_16, QAM_64 }; |
| 195 | static const enum fe_code_rate fec_tab[5] = { |
| 196 | FEC_1_2, FEC_2_3, FEC_3_4, FEC_5_6, FEC_7_8 |
| 197 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | u8 val; |
| 199 | |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 200 | dprintk ("%s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
| 202 | if (!(cx22700_readreg(state, 0x07) & 0x20)) /* tps valid? */ |
| 203 | return -EAGAIN; |
| 204 | |
| 205 | val = cx22700_readreg (state, 0x01); |
| 206 | |
| 207 | if ((val & 0x7) > 4) |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 208 | p->hierarchy = HIERARCHY_AUTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | else |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 210 | p->hierarchy = HIERARCHY_NONE + (val & 0x7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | if (((val >> 3) & 0x3) > 2) |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 213 | p->modulation = QAM_AUTO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | else |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 215 | p->modulation = qam_tab[(val >> 3) & 0x3]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | val = cx22700_readreg (state, 0x02); |
| 218 | |
| 219 | if (((val >> 3) & 0x07) > 4) |
| 220 | p->code_rate_HP = FEC_AUTO; |
| 221 | else |
| 222 | p->code_rate_HP = fec_tab[(val >> 3) & 0x07]; |
| 223 | |
| 224 | if ((val & 0x07) > 4) |
| 225 | p->code_rate_LP = FEC_AUTO; |
| 226 | else |
| 227 | p->code_rate_LP = fec_tab[val & 0x07]; |
| 228 | |
| 229 | val = cx22700_readreg (state, 0x03); |
| 230 | |
| 231 | p->guard_interval = GUARD_INTERVAL_1_32 + ((val >> 6) & 0x3); |
| 232 | p->transmission_mode = TRANSMISSION_MODE_2K + ((val >> 5) & 0x1); |
| 233 | |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | static int cx22700_init (struct dvb_frontend* fe) |
| 238 | |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 239 | { struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | int i; |
| 241 | |
| 242 | dprintk("cx22700_init: init chip\n"); |
| 243 | |
| 244 | cx22700_writereg (state, 0x00, 0x02); /* soft reset */ |
| 245 | cx22700_writereg (state, 0x00, 0x00); |
| 246 | |
| 247 | msleep(10); |
| 248 | |
| 249 | for (i=0; i<sizeof(init_tab); i+=2) |
| 250 | cx22700_writereg (state, init_tab[i], init_tab[i+1]); |
| 251 | |
| 252 | cx22700_writereg (state, 0x00, 0x01); |
| 253 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return 0; |
| 255 | } |
| 256 | |
Mauro Carvalho Chehab | 0df289a | 2015-06-07 14:53:52 -0300 | [diff] [blame] | 257 | static int cx22700_read_status(struct dvb_frontend *fe, enum fe_status *status) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 259 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) |
| 262 | | (cx22700_readreg (state, 0x0e) << 1); |
| 263 | u8 sync = cx22700_readreg (state, 0x07); |
| 264 | |
| 265 | *status = 0; |
| 266 | |
| 267 | if (rs_ber < 0xff00) |
| 268 | *status |= FE_HAS_SIGNAL; |
| 269 | |
| 270 | if (sync & 0x20) |
| 271 | *status |= FE_HAS_CARRIER; |
| 272 | |
| 273 | if (sync & 0x10) |
| 274 | *status |= FE_HAS_VITERBI; |
| 275 | |
| 276 | if (sync & 0x10) |
| 277 | *status |= FE_HAS_SYNC; |
| 278 | |
| 279 | if (*status == 0x0f) |
| 280 | *status |= FE_HAS_LOCK; |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | static int cx22700_read_ber(struct dvb_frontend* fe, u32* ber) |
| 286 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 287 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
| 289 | *ber = cx22700_readreg (state, 0x0c) & 0x7f; |
| 290 | cx22700_writereg (state, 0x0c, 0x00); |
| 291 | |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static int cx22700_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) |
| 296 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 297 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) |
| 300 | | (cx22700_readreg (state, 0x0e) << 1); |
| 301 | *signal_strength = ~rs_ber; |
| 302 | |
| 303 | return 0; |
| 304 | } |
| 305 | |
| 306 | static int cx22700_read_snr(struct dvb_frontend* fe, u16* snr) |
| 307 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 308 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | u16 rs_ber = (cx22700_readreg (state, 0x0d) << 9) |
| 311 | | (cx22700_readreg (state, 0x0e) << 1); |
| 312 | *snr = ~rs_ber; |
| 313 | |
| 314 | return 0; |
| 315 | } |
| 316 | |
| 317 | static int cx22700_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) |
| 318 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 319 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | *ucblocks = cx22700_readreg (state, 0x0f); |
| 322 | cx22700_writereg (state, 0x0f, 0x00); |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 327 | static int cx22700_set_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | { |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 329 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 330 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | cx22700_writereg (state, 0x00, 0x02); /* XXX CHECKME: soft reset*/ |
| 333 | cx22700_writereg (state, 0x00, 0x00); |
| 334 | |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 335 | if (fe->ops.tuner_ops.set_params) { |
Mauro Carvalho Chehab | 14d24d1 | 2011-12-24 12:24:33 -0300 | [diff] [blame] | 336 | fe->ops.tuner_ops.set_params(fe); |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 337 | if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); |
Andrew de Quincey | 5becb3b | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 338 | } |
| 339 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 340 | cx22700_set_inversion(state, c->inversion); |
| 341 | cx22700_set_tps(state, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | cx22700_writereg (state, 0x37, 0x01); /* PAL loop filter off */ |
| 343 | cx22700_writereg (state, 0x00, 0x01); /* restart acquire */ |
| 344 | |
| 345 | return 0; |
| 346 | } |
| 347 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 348 | static int cx22700_get_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 350 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 351 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | u8 reg09 = cx22700_readreg (state, 0x09); |
| 353 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 354 | c->inversion = reg09 & 0x1 ? INVERSION_ON : INVERSION_OFF; |
| 355 | return cx22700_get_tps(state, c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Andrew de Quincey | 5becb3b | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 358 | static int cx22700_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) |
| 359 | { |
| 360 | struct cx22700_state* state = fe->demodulator_priv; |
| 361 | |
| 362 | if (enable) { |
| 363 | return cx22700_writereg(state, 0x0a, 0x00); |
| 364 | } else { |
| 365 | return cx22700_writereg(state, 0x0a, 0x01); |
| 366 | } |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | static int cx22700_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings* fesettings) |
| 370 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 371 | fesettings->min_delay_ms = 150; |
| 372 | fesettings->step_size = 166667; |
| 373 | fesettings->max_drift = 166667*2; |
| 374 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | static void cx22700_release(struct dvb_frontend* fe) |
| 378 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 379 | struct cx22700_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | kfree(state); |
| 381 | } |
| 382 | |
| 383 | static struct dvb_frontend_ops cx22700_ops; |
| 384 | |
| 385 | struct dvb_frontend* cx22700_attach(const struct cx22700_config* config, |
| 386 | struct i2c_adapter* i2c) |
| 387 | { |
| 388 | struct cx22700_state* state = NULL; |
| 389 | |
| 390 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 391 | state = kzalloc(sizeof(struct cx22700_state), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | if (state == NULL) goto error; |
| 393 | |
| 394 | /* setup the state */ |
| 395 | state->config = config; |
| 396 | state->i2c = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
| 398 | /* check if the demod is there */ |
| 399 | if (cx22700_readreg(state, 0x07) < 0) goto error; |
| 400 | |
| 401 | /* create dvb_frontend */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 402 | memcpy(&state->frontend.ops, &cx22700_ops, sizeof(struct dvb_frontend_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | state->frontend.demodulator_priv = state; |
| 404 | return &state->frontend; |
| 405 | |
| 406 | error: |
| 407 | kfree(state); |
| 408 | return NULL; |
| 409 | } |
| 410 | |
| 411 | static struct dvb_frontend_ops cx22700_ops = { |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 412 | .delsys = { SYS_DVBT }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | .info = { |
| 414 | .name = "Conexant CX22700 DVB-T", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | .frequency_min = 470000000, |
| 416 | .frequency_max = 860000000, |
| 417 | .frequency_stepsize = 166667, |
| 418 | .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 419 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO | |
| 420 | FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 421 | FE_CAN_RECOVER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | }, |
| 423 | |
| 424 | .release = cx22700_release, |
| 425 | |
| 426 | .init = cx22700_init, |
Andrew de Quincey | 5becb3b | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 427 | .i2c_gate_ctrl = cx22700_i2c_gate_ctrl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
Mauro Carvalho Chehab | fd60721 | 2011-12-22 10:14:08 -0300 | [diff] [blame] | 429 | .set_frontend = cx22700_set_frontend, |
| 430 | .get_frontend = cx22700_get_frontend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | .get_tune_settings = cx22700_get_tune_settings, |
| 432 | |
| 433 | .read_status = cx22700_read_status, |
| 434 | .read_ber = cx22700_read_ber, |
| 435 | .read_signal_strength = cx22700_read_signal_strength, |
| 436 | .read_snr = cx22700_read_snr, |
| 437 | .read_ucblocks = cx22700_read_ucblocks, |
| 438 | }; |
| 439 | |
| 440 | module_param(debug, int, 0644); |
| 441 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 442 | |
| 443 | MODULE_DESCRIPTION("Conexant CX22700 DVB-T Demodulator driver"); |
| 444 | MODULE_AUTHOR("Holger Waechtler"); |
| 445 | MODULE_LICENSE("GPL"); |
| 446 | |
| 447 | EXPORT_SYMBOL(cx22700_attach); |