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