Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | Driver for Philips TDA8083 based QPSK Demodulator |
| 3 | |
| 4 | Copyright (C) 2001 Convergence Integrated Media GmbH |
| 5 | |
| 6 | written by Ralph Metzler <ralph@convergence.de> |
| 7 | |
| 8 | adoption to the new DVB frontend API and diagnostic ioctl's |
| 9 | by Holger Waechtler <holger@convergence.de> |
| 10 | |
| 11 | This program is free software; you can redistribute it and/or modify |
| 12 | it under the terms of the GNU General Public License as published by |
| 13 | the Free Software Foundation; either version 2 of the License, or |
| 14 | (at your option) any later version. |
| 15 | |
| 16 | This program is distributed in the hope that it will be useful, |
| 17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | GNU General Public License for more details. |
| 20 | |
| 21 | You should have received a copy of the GNU General Public License |
| 22 | along with this program; if not, write to the Free Software |
| 23 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | |
| 25 | */ |
| 26 | |
| 27 | #include <linux/init.h> |
| 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/string.h> |
| 31 | #include <linux/slab.h> |
Tim Schmielau | 4e57b68 | 2005-10-30 15:03:48 -0800 | [diff] [blame] | 32 | #include <linux/jiffies.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include "dvb_frontend.h" |
| 34 | #include "tda8083.h" |
| 35 | |
| 36 | |
| 37 | struct tda8083_state { |
| 38 | struct i2c_adapter* i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | /* configuration settings */ |
| 40 | const struct tda8083_config* config; |
| 41 | struct dvb_frontend frontend; |
| 42 | }; |
| 43 | |
| 44 | static int debug; |
| 45 | #define dprintk(args...) \ |
| 46 | do { \ |
| 47 | if (debug) printk(KERN_DEBUG "tda8083: " args); \ |
| 48 | } while (0) |
| 49 | |
| 50 | |
| 51 | static u8 tda8083_init_tab [] = { |
| 52 | 0x04, 0x00, 0x4a, 0x79, 0x04, 0x00, 0xff, 0xea, |
| 53 | 0x48, 0x42, 0x79, 0x60, 0x70, 0x52, 0x9a, 0x10, |
| 54 | 0x0e, 0x10, 0xf2, 0xa7, 0x93, 0x0b, 0x05, 0xc8, |
| 55 | 0x9d, 0x00, 0x42, 0x80, 0x00, 0x60, 0x40, 0x00, |
| 56 | 0x00, 0x75, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, |
| 57 | 0x00, 0x00, 0x00, 0x00 |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | static int tda8083_writereg (struct tda8083_state* state, u8 reg, u8 data) |
| 62 | { |
| 63 | int ret; |
| 64 | u8 buf [] = { reg, data }; |
| 65 | struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; |
| 66 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 67 | ret = i2c_transfer(state->i2c, &msg, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 69 | if (ret != 1) |
| 70 | dprintk ("%s: writereg error (reg %02x, ret == %i)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 71 | __func__, reg, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 73 | return (ret != 1) ? -1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static int tda8083_readregs (struct tda8083_state* state, u8 reg1, u8 *b, u8 len) |
| 77 | { |
| 78 | int ret; |
| 79 | struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = ®1, .len = 1 }, |
| 80 | { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b, .len = len } }; |
| 81 | |
| 82 | ret = i2c_transfer(state->i2c, msg, 2); |
| 83 | |
| 84 | if (ret != 2) |
| 85 | dprintk ("%s: readreg error (reg %02x, ret == %i)\n", |
Harvey Harrison | 271ddbf | 2008-04-08 23:20:00 -0300 | [diff] [blame] | 86 | __func__, reg1, ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 88 | return ret == 2 ? 0 : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static inline u8 tda8083_readreg (struct tda8083_state* state, u8 reg) |
| 92 | { |
| 93 | u8 val; |
| 94 | |
| 95 | tda8083_readregs (state, reg, &val, 1); |
| 96 | |
| 97 | return val; |
| 98 | } |
| 99 | |
| 100 | static int tda8083_set_inversion (struct tda8083_state* state, fe_spectral_inversion_t inversion) |
| 101 | { |
| 102 | /* XXX FIXME: implement other modes than FEC_AUTO */ |
| 103 | if (inversion == INVERSION_AUTO) |
| 104 | return 0; |
| 105 | |
| 106 | return -EINVAL; |
| 107 | } |
| 108 | |
| 109 | static int tda8083_set_fec (struct tda8083_state* state, fe_code_rate_t fec) |
| 110 | { |
| 111 | if (fec == FEC_AUTO) |
| 112 | return tda8083_writereg (state, 0x07, 0xff); |
| 113 | |
| 114 | if (fec >= FEC_1_2 && fec <= FEC_8_9) |
| 115 | return tda8083_writereg (state, 0x07, 1 << (FEC_8_9 - fec)); |
| 116 | |
| 117 | return -EINVAL; |
| 118 | } |
| 119 | |
| 120 | static fe_code_rate_t tda8083_get_fec (struct tda8083_state* state) |
| 121 | { |
| 122 | u8 index; |
| 123 | static fe_code_rate_t fec_tab [] = { FEC_8_9, FEC_1_2, FEC_2_3, FEC_3_4, |
| 124 | FEC_4_5, FEC_5_6, FEC_6_7, FEC_7_8 }; |
| 125 | |
| 126 | index = tda8083_readreg(state, 0x0e) & 0x07; |
| 127 | |
| 128 | return fec_tab [index]; |
| 129 | } |
| 130 | |
| 131 | static int tda8083_set_symbolrate (struct tda8083_state* state, u32 srate) |
| 132 | { |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 133 | u32 ratio; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | u32 tmp; |
| 135 | u8 filter; |
| 136 | |
| 137 | if (srate > 32000000) |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 138 | srate = 32000000; |
| 139 | if (srate < 500000) |
| 140 | srate = 500000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | filter = 0; |
| 143 | if (srate < 24000000) |
| 144 | filter = 2; |
| 145 | if (srate < 16000000) |
| 146 | filter = 3; |
| 147 | |
| 148 | tmp = 31250 << 16; |
| 149 | ratio = tmp / srate; |
| 150 | |
| 151 | tmp = (tmp % srate) << 8; |
| 152 | ratio = (ratio << 8) + tmp / srate; |
| 153 | |
| 154 | tmp = (tmp % srate) << 8; |
| 155 | ratio = (ratio << 8) + tmp / srate; |
| 156 | |
| 157 | dprintk("tda8083: ratio == %08x\n", (unsigned int) ratio); |
| 158 | |
| 159 | tda8083_writereg (state, 0x05, filter); |
| 160 | tda8083_writereg (state, 0x02, (ratio >> 16) & 0xff); |
| 161 | tda8083_writereg (state, 0x03, (ratio >> 8) & 0xff); |
| 162 | tda8083_writereg (state, 0x04, (ratio ) & 0xff); |
| 163 | |
| 164 | tda8083_writereg (state, 0x00, 0x3c); |
| 165 | tda8083_writereg (state, 0x00, 0x04); |
| 166 | |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | static void tda8083_wait_diseqc_fifo (struct tda8083_state* state, int timeout) |
| 171 | { |
| 172 | unsigned long start = jiffies; |
| 173 | |
| 174 | while (jiffies - start < timeout && |
Mauro Carvalho Chehab | 9101e62 | 2005-12-12 00:37:24 -0800 | [diff] [blame] | 175 | !(tda8083_readreg(state, 0x02) & 0x80)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | { |
| 177 | msleep(50); |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static int tda8083_set_tone (struct tda8083_state* state, fe_sec_tone_mode_t tone) |
| 182 | { |
| 183 | tda8083_writereg (state, 0x26, 0xf1); |
| 184 | |
| 185 | switch (tone) { |
| 186 | case SEC_TONE_OFF: |
| 187 | return tda8083_writereg (state, 0x29, 0x00); |
| 188 | case SEC_TONE_ON: |
| 189 | return tda8083_writereg (state, 0x29, 0x80); |
| 190 | default: |
| 191 | return -EINVAL; |
Joe Perches | 2028c71 | 2013-10-08 20:29:08 -0300 | [diff] [blame] | 192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | static int tda8083_set_voltage (struct tda8083_state* state, fe_sec_voltage_t voltage) |
| 196 | { |
| 197 | switch (voltage) { |
| 198 | case SEC_VOLTAGE_13: |
| 199 | return tda8083_writereg (state, 0x20, 0x00); |
| 200 | case SEC_VOLTAGE_18: |
| 201 | return tda8083_writereg (state, 0x20, 0x11); |
| 202 | default: |
| 203 | return -EINVAL; |
Joe Perches | 2028c71 | 2013-10-08 20:29:08 -0300 | [diff] [blame] | 204 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static int tda8083_send_diseqc_burst (struct tda8083_state* state, fe_sec_mini_cmd_t burst) |
| 208 | { |
| 209 | switch (burst) { |
| 210 | case SEC_MINI_A: |
| 211 | tda8083_writereg (state, 0x29, (5 << 2)); /* send burst A */ |
| 212 | break; |
| 213 | case SEC_MINI_B: |
| 214 | tda8083_writereg (state, 0x29, (7 << 2)); /* send B */ |
| 215 | break; |
| 216 | default: |
| 217 | return -EINVAL; |
Peter Senna Tschudin | c2c1b41 | 2012-09-28 05:37:22 -0300 | [diff] [blame] | 218 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | tda8083_wait_diseqc_fifo (state, 100); |
| 221 | |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static int tda8083_send_diseqc_msg (struct dvb_frontend* fe, |
| 226 | struct dvb_diseqc_master_cmd *m) |
| 227 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 228 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | int i; |
| 230 | |
| 231 | tda8083_writereg (state, 0x29, (m->msg_len - 3) | (1 << 2)); /* enable */ |
| 232 | |
| 233 | for (i=0; i<m->msg_len; i++) |
| 234 | tda8083_writereg (state, 0x23 + i, m->msg[i]); |
| 235 | |
| 236 | tda8083_writereg (state, 0x29, (m->msg_len - 3) | (3 << 2)); /* send!! */ |
| 237 | |
| 238 | tda8083_wait_diseqc_fifo (state, 100); |
| 239 | |
| 240 | return 0; |
| 241 | } |
| 242 | |
| 243 | static int tda8083_read_status(struct dvb_frontend* fe, fe_status_t* status) |
| 244 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 245 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | |
| 247 | u8 signal = ~tda8083_readreg (state, 0x01); |
| 248 | u8 sync = tda8083_readreg (state, 0x02); |
| 249 | |
| 250 | *status = 0; |
| 251 | |
| 252 | if (signal > 10) |
| 253 | *status |= FE_HAS_SIGNAL; |
| 254 | |
| 255 | if (sync & 0x01) |
| 256 | *status |= FE_HAS_CARRIER; |
| 257 | |
| 258 | if (sync & 0x02) |
| 259 | *status |= FE_HAS_VITERBI; |
| 260 | |
| 261 | if (sync & 0x10) |
| 262 | *status |= FE_HAS_SYNC; |
| 263 | |
Christoph Haubrich | dbb2e63 | 2006-10-31 00:29:30 -0300 | [diff] [blame] | 264 | if (sync & 0x20) /* frontend can not lock */ |
| 265 | *status |= FE_TIMEDOUT; |
| 266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | if ((sync & 0x1f) == 0x1f) |
| 268 | *status |= FE_HAS_LOCK; |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Christoph Haubrich | dbb2e63 | 2006-10-31 00:29:30 -0300 | [diff] [blame] | 273 | static int tda8083_read_ber(struct dvb_frontend* fe, u32* ber) |
| 274 | { |
| 275 | struct tda8083_state* state = fe->demodulator_priv; |
| 276 | int ret; |
| 277 | u8 buf[3]; |
| 278 | |
| 279 | if ((ret = tda8083_readregs(state, 0x0b, buf, sizeof(buf)))) |
| 280 | return ret; |
| 281 | |
| 282 | *ber = ((buf[0] & 0x1f) << 16) | (buf[1] << 8) | buf[2]; |
| 283 | |
| 284 | return 0; |
| 285 | } |
| 286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | static int tda8083_read_signal_strength(struct dvb_frontend* fe, u16* strength) |
| 288 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 289 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | u8 signal = ~tda8083_readreg (state, 0x01); |
| 292 | *strength = (signal << 8) | signal; |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int tda8083_read_snr(struct dvb_frontend* fe, u16* snr) |
| 298 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 299 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | u8 _snr = tda8083_readreg (state, 0x08); |
| 302 | *snr = (_snr << 8) | _snr; |
| 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
Christoph Haubrich | dbb2e63 | 2006-10-31 00:29:30 -0300 | [diff] [blame] | 307 | static int tda8083_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks) |
| 308 | { |
| 309 | struct tda8083_state* state = fe->demodulator_priv; |
| 310 | |
| 311 | *ucblocks = tda8083_readreg(state, 0x0f); |
| 312 | if (*ucblocks == 0xff) |
| 313 | *ucblocks = 0xffffffff; |
| 314 | |
| 315 | return 0; |
| 316 | } |
| 317 | |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 318 | static int tda8083_set_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 320 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 321 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | d21eac0 | 2006-04-18 17:47:09 -0300 | [diff] [blame] | 326 | } |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | tda8083_set_inversion (state, p->inversion); |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 329 | tda8083_set_fec(state, p->fec_inner); |
| 330 | tda8083_set_symbolrate(state, p->symbol_rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | tda8083_writereg (state, 0x00, 0x3c); |
| 333 | tda8083_writereg (state, 0x00, 0x04); |
| 334 | |
| 335 | return 0; |
| 336 | } |
| 337 | |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 338 | static int tda8083_get_frontend(struct dvb_frontend *fe) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Mauro Carvalho Chehab | 7c61d80 | 2011-12-30 11:30:21 -0300 | [diff] [blame] | 340 | struct dtv_frontend_properties *p = &fe->dtv_property_cache; |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 341 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* FIXME: get symbolrate & frequency offset...*/ |
| 344 | /*p->frequency = ???;*/ |
| 345 | p->inversion = (tda8083_readreg (state, 0x0e) & 0x80) ? |
| 346 | INVERSION_ON : INVERSION_OFF; |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 347 | p->fec_inner = tda8083_get_fec(state); |
| 348 | /*p->symbol_rate = tda8083_get_symbolrate (state);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | static int tda8083_sleep(struct dvb_frontend* fe) |
| 354 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 355 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | tda8083_writereg (state, 0x00, 0x02); |
| 358 | return 0; |
| 359 | } |
| 360 | |
| 361 | static int tda8083_init(struct dvb_frontend* fe) |
| 362 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 363 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | int i; |
| 365 | |
| 366 | for (i=0; i<44; i++) |
| 367 | tda8083_writereg (state, i, tda8083_init_tab[i]); |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | tda8083_writereg (state, 0x00, 0x3c); |
| 370 | tda8083_writereg (state, 0x00, 0x04); |
| 371 | |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | static int tda8083_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) |
| 376 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 377 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
| 379 | tda8083_send_diseqc_burst (state, burst); |
| 380 | tda8083_writereg (state, 0x00, 0x3c); |
| 381 | tda8083_writereg (state, 0x00, 0x04); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static int tda8083_diseqc_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone) |
| 387 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 388 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | tda8083_set_tone (state, tone); |
| 391 | tda8083_writereg (state, 0x00, 0x3c); |
| 392 | tda8083_writereg (state, 0x00, 0x04); |
| 393 | |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | static int tda8083_diseqc_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage) |
| 398 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 399 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | tda8083_set_voltage (state, voltage); |
| 402 | tda8083_writereg (state, 0x00, 0x3c); |
| 403 | tda8083_writereg (state, 0x00, 0x04); |
| 404 | |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | static void tda8083_release(struct dvb_frontend* fe) |
| 409 | { |
Johannes Stezenbach | b874270 | 2005-05-16 21:54:31 -0700 | [diff] [blame] | 410 | struct tda8083_state* state = fe->demodulator_priv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | kfree(state); |
| 412 | } |
| 413 | |
| 414 | static struct dvb_frontend_ops tda8083_ops; |
| 415 | |
| 416 | struct dvb_frontend* tda8083_attach(const struct tda8083_config* config, |
| 417 | struct i2c_adapter* i2c) |
| 418 | { |
| 419 | struct tda8083_state* state = NULL; |
| 420 | |
| 421 | /* allocate memory for the internal state */ |
Matthias Schwarzott | 084e24a | 2009-08-10 22:51:01 -0300 | [diff] [blame] | 422 | state = kzalloc(sizeof(struct tda8083_state), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (state == NULL) goto error; |
| 424 | |
| 425 | /* setup the state */ |
| 426 | state->config = config; |
| 427 | state->i2c = i2c; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | |
| 429 | /* check if the demod is there */ |
| 430 | if ((tda8083_readreg(state, 0x00)) != 0x05) goto error; |
| 431 | |
| 432 | /* create dvb_frontend */ |
Patrick Boettcher | dea7486 | 2006-05-14 05:01:31 -0300 | [diff] [blame] | 433 | memcpy(&state->frontend.ops, &tda8083_ops, sizeof(struct dvb_frontend_ops)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | state->frontend.demodulator_priv = state; |
| 435 | return &state->frontend; |
| 436 | |
| 437 | error: |
| 438 | kfree(state); |
| 439 | return NULL; |
| 440 | } |
| 441 | |
| 442 | static struct dvb_frontend_ops tda8083_ops = { |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 443 | .delsys = { SYS_DVBS }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | .info = { |
| 445 | .name = "Philips TDA8083 DVB-S", |
Oliver Endriss | 4f76b67 | 2007-08-06 13:59:19 -0300 | [diff] [blame] | 446 | .frequency_min = 920000, /* TDA8060 */ |
| 447 | .frequency_max = 2200000, /* TDA8060 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | .frequency_stepsize = 125, /* kHz for QPSK frontends */ |
| 449 | /* .frequency_tolerance = ???,*/ |
Oliver Endriss | 4f76b67 | 2007-08-06 13:59:19 -0300 | [diff] [blame] | 450 | .symbol_rate_min = 12000000, |
| 451 | .symbol_rate_max = 30000000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* .symbol_rate_tolerance = ???,*/ |
| 453 | .caps = FE_CAN_INVERSION_AUTO | |
| 454 | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 | |
| 455 | FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 | |
| 456 | FE_CAN_FEC_7_8 | FE_CAN_FEC_8_9 | FE_CAN_FEC_AUTO | |
| 457 | FE_CAN_QPSK | FE_CAN_MUTE_TS |
| 458 | }, |
| 459 | |
| 460 | .release = tda8083_release, |
| 461 | |
| 462 | .init = tda8083_init, |
| 463 | .sleep = tda8083_sleep, |
| 464 | |
Mauro Carvalho Chehab | 042e5eb | 2011-12-26 15:07:36 -0300 | [diff] [blame] | 465 | .set_frontend = tda8083_set_frontend, |
| 466 | .get_frontend = tda8083_get_frontend, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
| 468 | .read_status = tda8083_read_status, |
| 469 | .read_signal_strength = tda8083_read_signal_strength, |
| 470 | .read_snr = tda8083_read_snr, |
Christoph Haubrich | dbb2e63 | 2006-10-31 00:29:30 -0300 | [diff] [blame] | 471 | .read_ber = tda8083_read_ber, |
| 472 | .read_ucblocks = tda8083_read_ucblocks, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | .diseqc_send_master_cmd = tda8083_send_diseqc_msg, |
| 475 | .diseqc_send_burst = tda8083_diseqc_send_burst, |
| 476 | .set_tone = tda8083_diseqc_set_tone, |
| 477 | .set_voltage = tda8083_diseqc_set_voltage, |
| 478 | }; |
| 479 | |
| 480 | module_param(debug, int, 0644); |
| 481 | MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); |
| 482 | |
| 483 | MODULE_DESCRIPTION("Philips TDA8083 DVB-S Demodulator"); |
| 484 | MODULE_AUTHOR("Ralph Metzler, Holger Waechtler"); |
| 485 | MODULE_LICENSE("GPL"); |
| 486 | |
| 487 | EXPORT_SYMBOL(tda8083_attach); |