24 #include <linux/module.h>
25 #include <linux/device.h>
27 #include <linux/string.h>
28 #include <linux/slab.h>
33 #define SACLK 96000000
47 #define dprintk(args...) \
49 if (debug) printk(KERN_DEBUG "tda10086: " args); \
55 u8 b0[] = {
reg, data };
56 struct i2c_msg msg = { .
flags = 0, .buf = b0, .len = 2 };
62 dprintk(
"%s: error reg=0x%x, data=0x%x, ret=%i\n",
63 __func__, reg, data, ret);
65 return (ret != 1) ? ret : 0;
73 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
74 { .flags =
I2C_M_RD, .buf = b1, .len = 1 }};
81 dprintk(
"%s: error reg=0x%x, ret=%i\n", __func__, reg,
94 val = tda10086_read_byte(state, reg);
103 return tda10086_write_byte(state, reg, val);
113 if (state->
config->diseqc_tone)
116 tda10086_write_byte(state, 0x00, 0x00);
120 tda10086_write_byte(state, 0x01, 0x94);
121 tda10086_write_byte(state, 0x02, 0x35);
122 tda10086_write_byte(state, 0x03, 0xe4);
123 tda10086_write_byte(state, 0x04, 0x43);
124 tda10086_write_byte(state, 0x0c, 0x0c);
125 tda10086_write_byte(state, 0x1b, 0xb0);
126 tda10086_write_byte(state, 0x20, 0x89);
127 tda10086_write_byte(state, 0x30, 0x04);
128 tda10086_write_byte(state, 0x32, 0x00);
129 tda10086_write_byte(state, 0x31, 0x56);
132 tda10086_write_byte(state, 0x55, 0x2c);
134 tda10086_write_byte(state, 0x3a, 0x0b);
135 tda10086_write_byte(state, 0x3b, 0x01);
137 tda10086_write_byte(state, 0x3a, 0x17);
138 tda10086_write_byte(state, 0x3b, 0x00);
140 tda10086_write_mask(state, 0x55, 0x20, 0x00);
143 tda10086_write_byte(state, 0x11, 0x81);
144 tda10086_write_byte(state, 0x12, 0x81);
145 tda10086_write_byte(state, 0x19, 0x40);
146 tda10086_write_byte(state, 0x56, 0x80);
147 tda10086_write_byte(state, 0x57, 0x08);
148 tda10086_write_byte(state, 0x10, 0x2a);
151 tda10086_write_byte(state, 0x58, 0x61);
152 tda10086_write_mask(state, 0x58, 0x01, 0x00);
155 tda10086_write_byte(state, 0x05, 0x0B);
156 tda10086_write_byte(state, 0x37, 0x63);
157 tda10086_write_byte(state, 0x3f, 0x0a);
158 tda10086_write_byte(state, 0x40, 0x64);
159 tda10086_write_byte(state, 0x41, 0x4f);
160 tda10086_write_byte(state, 0x42, 0x43);
163 tda10086_write_byte(state, 0x1a, 0x11);
166 tda10086_write_byte(state, 0x3d, 0x80);
169 tda10086_write_byte(state, 0x36, t22k_off);
170 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (
SACLK/1000)));
171 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (
SACLK/1000)) >> 8);
179 while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
181 printk(
"%s: diseqc queue not ready, command may be lost.\n", __func__);
195 if (state->
config->diseqc_tone)
200 tda10086_write_byte(state, 0x36, t22k_off);
204 tda10086_write_byte(state, 0x36, 0x01 + t22k_off);
211 static int tda10086_send_master_cmd (
struct dvb_frontend* fe,
221 if (state->
config->diseqc_tone)
226 oldval = tda10086_read_byte(state, 0x36);
228 for(i=0; i< cmd->
msg_len; i++) {
229 tda10086_write_byte(state, 0x48+i, cmd->
msg[i]);
231 tda10086_write_byte(state, 0x36, (0x08 + t22k_off)
234 tda10086_diseqc_wait(state);
236 tda10086_write_byte(state, 0x36, oldval);
244 u8 oldval = tda10086_read_byte(state, 0x36);
249 if (state->
config->diseqc_tone)
254 tda10086_write_byte(state, 0x36, 0x04 + t22k_off);
258 tda10086_write_byte(state, 0x36, 0x06 + t22k_off);
262 tda10086_diseqc_wait(state);
264 tda10086_write_byte(state, 0x36, oldval);
278 if (state->
config->invert)
282 if (!state->
config->invert)
289 tda10086_write_mask(state, 0x0c, 0xc0, invval);
308 dprintk (
"%s %i\n", __func__, symbol_rate);
311 if (symbol_rate < (
u32) (
SACLK * 0.0137)) {
314 }
else if (symbol_rate < (
u32) (
SACLK * 0.0208)) {
317 }
else if (symbol_rate < (
u32) (
SACLK * 0.0270)) {
320 }
else if (symbol_rate < (
u32) (
SACLK * 0.0416)) {
323 }
else if (symbol_rate < (
u32) (
SACLK * 0.0550)) {
326 }
else if (symbol_rate < (
u32) (
SACLK * 0.0833)) {
329 }
else if (symbol_rate < (
u32) (
SACLK * 0.1100)) {
332 }
else if (symbol_rate < (
u32) (
SACLK * 0.1666)) {
335 }
else if (symbol_rate < (
u32) (
SACLK * 0.2200)) {
338 }
else if (symbol_rate < (
u32) (
SACLK * 0.3333)) {
348 big = (1ULL<<21) * ((
u64) symbol_rate/1000ULL) * (1ULL<<dfn);
349 big += ((
SACLK/1000ULL)-1ULL);
354 tmp = (1<<dfn)*(symbol_rate/1000);
355 bdri = ((32 * (
SACLK/1000)) + (tmp-1)) /
tmp;
357 tda10086_write_byte(state, 0x21, (afs << 7) | dfn);
358 tda10086_write_mask(state, 0x20, 0x08, byp << 3);
359 tda10086_write_byte(state, 0x06, bdr);
360 tda10086_write_byte(state, 0x07, bdr >> 8);
361 tda10086_write_byte(state, 0x08, bdr >> 16);
362 tda10086_write_byte(state, 0x09, bdri);
363 tda10086_write_byte(state, 0x37, reg37);
364 tda10086_write_byte(state, 0x42, reg42);
407 tda10086_write_byte(state, 0x0d, fecval);
412 static int tda10086_set_frontend(
struct dvb_frontend *fe)
423 tda10086_write_byte(state, 0x02, 0x35);
427 if (fe->
ops.tuner_ops.set_params) {
428 fe->
ops.tuner_ops.set_params(fe);
429 if (fe->
ops.i2c_gate_ctrl)
430 fe->
ops.i2c_gate_ctrl(fe, 0);
432 if (fe->
ops.tuner_ops.get_frequency)
433 fe->
ops.tuner_ops.get_frequency(fe, &freq);
434 if (fe->
ops.i2c_gate_ctrl)
435 fe->
ops.i2c_gate_ctrl(fe, 0);
440 freqoff = ((1<<16) * freqoff) / (
SACLK/1000);
441 tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f));
442 tda10086_write_byte(state, 0x3e, freqoff);
444 if ((ret = tda10086_set_inversion(state, fe_params)) < 0)
446 if ((ret = tda10086_set_symbol_rate(state, fe_params)) < 0)
448 if ((ret = tda10086_set_fec(state, fe_params)) < 0)
452 tda10086_write_mask(state, 0x10, 0x40, 0x40);
453 tda10086_write_mask(state, 0x00, 0x01, 0x00);
460 static int tda10086_get_frontend(
struct dvb_frontend *fe)
475 tmp64 = tda10086_read_byte(state, 0x52);
476 tmp64 |= (tda10086_read_byte(state, 0x51) << 8);
478 tmp64 |= 0xffffffffffff0000ULL;
479 tmp64 = (tmp64 * (
SACLK/1000ULL));
480 do_div(tmp64, (1ULL<<15) * (1ULL<<1));
484 val = tda10086_read_byte(state, 0x0c);
489 if (state->
config->invert)
494 if (state->
config->invert)
499 tda10086_read_byte(state, 0x0f);
503 if (state->
config->invert)
508 if (state->
config->invert)
515 tmp = tda10086_read_byte(state, 0x1d);
518 tmp = (tmp * 480 * (1<<1)) / 128;
519 tmp = ((state->
symbol_rate/1000) * tmp) / (1000000/1000);
523 val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4;
561 val = tda10086_read_byte(state, 0x0e);
576 tda10086_write_byte(state, 0x02, 0x00);
583 static int tda10086_read_signal_strength(
struct dvb_frontend* fe,
u16 * signal)
590 _str = 0xff - tda10086_read_byte(state, 0x43);
591 *signal = (_str << 8) | _str;
603 _snr = 0xff - tda10086_read_byte(state, 0x1c);
604 *snr = (_snr << 8) | _snr;
609 static int tda10086_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
616 *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
619 tda10086_write_byte(state, 0x18, 0x00);
620 tda10086_write_byte(state, 0x18, 0x80);
633 *ber |= tda10086_read_byte(state, 0x15);
634 *ber |= tda10086_read_byte(state, 0x16) << 8;
635 *ber |= (tda10086_read_byte(state, 0x17) & 0xf) << 16;
646 tda10086_write_mask(state, 0x00, 0x08, 0x08);
658 tda10086_write_mask(state, 0x00, 0x10, 0x10);
660 tda10086_write_mask(state, 0x00, 0x10, 0x00);
709 .name =
"Philips TDA10086 DVB-S",
710 .frequency_min = 950000,
711 .frequency_max = 2150000,
712 .frequency_stepsize = 125,
713 .symbol_rate_min = 1000000,
714 .symbol_rate_max = 45000000,
721 .release = tda10086_release,
723 .init = tda10086_init,
724 .sleep = tda10086_sleep,
725 .i2c_gate_ctrl = tda10086_i2c_gate_ctrl,
727 .set_frontend = tda10086_set_frontend,
728 .get_frontend = tda10086_get_frontend,
729 .get_tune_settings = tda10086_get_tune_settings,
731 .read_status = tda10086_read_status,
732 .read_ber = tda10086_read_ber,
733 .read_signal_strength = tda10086_read_signal_strength,
734 .read_snr = tda10086_read_snr,
735 .read_ucblocks = tda10086_read_ucblocks,
737 .diseqc_send_master_cmd = tda10086_send_master_cmd,
738 .diseqc_send_burst = tda10086_send_burst,
739 .set_tone = tda10086_set_tone,
759 if (tda10086_read_byte(state, 0x1e) != 0xe1) {