26 #include <linux/module.h>
27 #include <linux/device.h>
29 #include <linux/string.h>
30 #include <linux/slab.h>
31 #include <linux/types.h>
49 static int m88rs2000_debug;
54 #define dprintk(level, args...) do { \
55 if (level & m88rs2000_debug) \
56 printk(KERN_DEBUG "m88rs2000-fe: " args); \
59 #define deb_info(args...) dprintk(0x01, args)
60 #define info(format, arg...) \
61 printk(KERN_INFO "m88rs2000-fe: " format "\n" , ## arg)
69 u8 buf[] = { reg, data };
80 deb_info(
"%s: writereg error (reg == 0x%02x, val == 0x%02x, "
88 return m88rs2000_writereg(state, 1, reg, data);
93 m88rs2000_demod_write(state, 0x81, 0x84);
95 return m88rs2000_writereg(state, 0, reg, data);
106 return m88rs2000_writereg(state, 1, buf[0], buf[1]);
115 state->
config->demod_addr;
133 deb_info(
"%s: readreg error (reg == 0x%02x, ret == %i)\n",
141 return m88rs2000_readreg(state, 1, reg);
146 m88rs2000_demod_write(state, 0x81, 0x85);
148 return m88rs2000_readreg(state, 0, reg);
151 static int m88rs2000_set_symbolrate(
struct dvb_frontend *fe,
u32 srate)
158 if ((srate < 1000000) || (srate > 45000000))
166 b[0] = (
u8) (temp >> 16) & 0xff;
167 b[1] = (
u8) (temp >> 8) & 0xff;
168 b[2] = (
u8) temp & 0xff;
169 ret = m88rs2000_demod_write(state, 0x93, b[2]);
170 ret |= m88rs2000_demod_write(state, 0x94, b[1]);
171 ret |= m88rs2000_demod_write(state, 0x95, b[0]);
173 deb_info(
"m88rs2000: m88rs2000_set_symbolrate\n");
177 static int m88rs2000_send_diseqc_msg(
struct dvb_frontend *fe,
185 m88rs2000_demod_write(state, 0x9a, 0x30);
186 reg = m88rs2000_demod_read(state, 0xb2);
188 m88rs2000_demod_write(state, 0xb2, reg);
189 for (i = 0; i < m->
msg_len; i++)
190 m88rs2000_demod_write(state, 0xb3 + i, m->
msg[i]);
192 reg = m88rs2000_demod_read(state, 0xb1);
194 reg |= ((m->
msg_len - 1) << 3) | 0x07;
196 m88rs2000_demod_write(state, 0xb1, reg);
198 for (i = 0; i < 15; i++) {
199 if ((m88rs2000_demod_read(state, 0xb1) & 0x40) == 0x0)
204 reg = m88rs2000_demod_read(state, 0xb1);
205 if ((reg & 0x40) > 0x0) {
208 m88rs2000_demod_write(state, 0xb1, reg);
211 reg = m88rs2000_demod_read(state, 0xb2);
214 m88rs2000_demod_write(state, 0xb2, reg);
215 m88rs2000_demod_write(state, 0x9a, 0xb0);
221 static int m88rs2000_send_diseqc_burst(
struct dvb_frontend *fe,
227 m88rs2000_demod_write(state, 0x9a, 0x30);
229 reg0 = m88rs2000_demod_read(state, 0xb1);
230 reg1 = m88rs2000_demod_read(state, 0xb2);
232 m88rs2000_demod_write(state, 0xb2, reg1);
233 m88rs2000_demod_write(state, 0xb1, reg0);
234 m88rs2000_demod_write(state, 0x9a, 0xb0);
243 m88rs2000_demod_write(state, 0x9a, 0x30);
244 reg0 = m88rs2000_demod_read(state, 0xb1);
245 reg1 = m88rs2000_demod_read(state, 0xb2);
260 m88rs2000_demod_write(state, 0xb2, reg1);
261 m88rs2000_demod_write(state, 0xb1, reg0);
262 m88rs2000_demod_write(state, 0x9a, 0xb0);
389 for (i = 0; i < 255; i++) {
390 switch (tab[i].
cmd) {
392 ret = m88rs2000_demod_write(state, tab[i].reg,
396 ret = m88rs2000_tuner_write(state, tab[i].reg,
404 if (tab[i].reg == 0xaa && tab[i].
val == 0xff)
422 data = m88rs2000_demod_read(state, 0xb2);
437 m88rs2000_demod_write(state, 0xb2, data);
447 reg = m88rs2000_tuner_read(state, 0x00);
448 if ((reg & 0x40) == 0)
461 ret = m88rs2000_tab_set(state, m88rs2000_setup);
471 ret = m88rs2000_tab_set(state, m88rs2000_shutdown);
478 u8 reg = m88rs2000_demod_read(state, 0x8c);
482 if ((reg & 0x7) == 0x7) {
485 if (state->
config->set_ts_params)
495 deb_info(
"m88rs2000_read_ber %d\n", *ber);
500 static int m88rs2000_read_signal_strength(
struct dvb_frontend *fe,
509 deb_info(
"m88rs2000_read_snr %d\n", *snr);
514 static int m88rs2000_read_ucblocks(
struct dvb_frontend *fe,
u32 *ucblocks)
516 deb_info(
"m88rs2000_read_ber %d\n", *ucblocks);
524 ret = m88rs2000_tuner_write(state, 0x51, 0x1f - offset);
525 ret |= m88rs2000_tuner_write(state, 0x51, 0x1f);
526 ret |= m88rs2000_tuner_write(state, 0x50, offset);
527 ret |= m88rs2000_tuner_write(state, 0x50, 0x00);
532 static int m88rs2000_set_tuner_rf(
struct dvb_frontend *fe)
536 reg = m88rs2000_tuner_read(state, 0x3d);
540 else if (reg == 0x16)
545 m88rs2000_tuner_write(state, 0x60, reg);
546 reg = m88rs2000_tuner_gate_ctrl(state, 0x08);
548 if (fe->
ops.i2c_gate_ctrl)
549 fe->
ops.i2c_gate_ctrl(fe, 0);
564 u8 lpf_mxdiv, mlpf_max, mlpf_min, nlpf;
568 ret = m88rs2000_tab_set(state, tuner_reset);
571 if (frequency < 1060000) {
577 ndiv = ndiv + ndiv % 2;
580 ret = m88rs2000_tuner_write(state, 0x10, 0x80 | lo);
583 ret |= m88rs2000_tuner_write(state, 0x01, (ndiv >> 8) & 0xf);
584 ret |= m88rs2000_tuner_write(state, 0x02, ndiv & 0xff);
586 ret |= m88rs2000_tuner_write(state, 0x03, 0x06);
587 ret |= m88rs2000_tuner_gate_ctrl(state, 0x10);
592 ret = m88rs2000_tuner_write(state, 0x10, lo);
594 ret |= m88rs2000_tuner_gate_ctrl(state, 0x08);
597 ret |= m88rs2000_set_tuner_rf(fe);
600 ret |= m88rs2000_tuner_write(state, 0x04, gdiv28 & 0xff);
601 ret |= m88rs2000_tuner_gate_ctrl(state, 0x04);
605 value = m88rs2000_tuner_read(state, 0x26);
607 f3db = (symbol_rate * 135) / 200 + 2000;
614 gdiv28 = gdiv28 * 207 / (value * 2 + 151);
615 mlpf_max = gdiv28 * 135 / 100;
616 mlpf_min = gdiv28 * 78 / 100;
622 nlpf = (f3db * gdiv28 * 2 / lpf_coeff /
630 * lpf_coeff * 2 / f3db + 1) / 2;
632 if (lpf_mxdiv < mlpf_min) {
635 * lpf_coeff * 2 / f3db + 1) / 2;
638 if (lpf_mxdiv > mlpf_max)
639 lpf_mxdiv = mlpf_max;
641 ret = m88rs2000_tuner_write(state, 0x04, lpf_mxdiv);
642 ret |= m88rs2000_tuner_write(state, 0x06, nlpf);
644 ret |= m88rs2000_tuner_gate_ctrl(state, 0x04);
646 ret |= m88rs2000_tuner_gate_ctrl(state, 0x01);
651 / 14 / (
div4 + 1) / 2;
658 tmp = (2 * tmp + 96000) / (2 * 96000);
662 *offset = tmp & 0xffff;
664 if (fe->
ops.i2c_gate_ctrl)
665 fe->
ops.i2c_gate_ctrl(fe, 0);
667 return (ret < 0) ? -
EINVAL : 0;
695 m88rs2000_demod_write(state, 0x76, fec_set);
704 m88rs2000_demod_write(state, 0x9a, 0x30);
705 reg = m88rs2000_demod_read(state, 0x76);
706 m88rs2000_demod_write(state, 0x9a, 0xb0);
727 static int m88rs2000_set_frontend(
struct dvb_frontend *fe)
739 deb_info(
"%s: unsupported delivery "
740 "system selected (%d)\n",
746 ret = m88rs2000_set_tuner(fe, &offset);
750 ret = m88rs2000_demod_write(state, 0x9a, 0x30);
752 reg = m88rs2000_demod_read(state, 0
x86);
753 ret |= m88rs2000_demod_write(state, 0
x86, reg);
755 ret |= m88rs2000_demod_write(state, 0x9c, (offset >> 8));
756 ret |= m88rs2000_demod_write(state, 0x9d, offset & 0xf0);
760 ret = m88rs2000_tab_set(state, fe_reset);
765 reg = m88rs2000_demod_read(state, 0x70);
766 ret = m88rs2000_demod_write(state, 0x70, reg);
769 ret |= m88rs2000_set_fec(state, c->
fec_inner);
770 ret |= m88rs2000_demod_write(state, 0x85, 0x1);
771 ret |= m88rs2000_demod_write(state, 0x8a, 0xbf);
772 ret |= m88rs2000_demod_write(state, 0x8d, 0x1e);
773 ret |= m88rs2000_demod_write(state, 0x90, 0xf1);
774 ret |= m88rs2000_demod_write(state, 0x91, 0x08);
780 ret = m88rs2000_set_symbolrate(fe, c->
symbol_rate);
785 ret = m88rs2000_tab_set(state, fe_trigger);
789 for (i = 0; i < 25; i++) {
790 reg = m88rs2000_demod_read(state, 0x8c);
791 if ((reg & 0x7) == 0x7) {
797 reg = m88rs2000_demod_read(state, 0x70);
799 m88rs2000_demod_write(state, 0x70, reg);
803 m88rs2000_set_tuner_rf(fe);
808 state->
fec_inner = m88rs2000_get_fec(state);
810 reg = m88rs2000_demod_read(state, 0x65);
818 static int m88rs2000_get_frontend(
struct dvb_frontend *fe)
833 m88rs2000_demod_write(state, 0x81, 0x84);
835 m88rs2000_demod_write(state, 0x81, 0x81);
849 .name =
"M88RS2000 DVB-S",
850 .frequency_min = 950000,
851 .frequency_max = 2150000,
852 .frequency_stepsize = 1000,
853 .frequency_tolerance = 5000,
854 .symbol_rate_min = 1000000,
855 .symbol_rate_max = 45000000,
856 .symbol_rate_tolerance = 500,
863 .release = m88rs2000_release,
864 .init = m88rs2000_init,
865 .sleep = m88rs2000_sleep,
866 .write = m88rs2000_write,
867 .i2c_gate_ctrl = m88rs2000_i2c_gate_ctrl,
868 .read_status = m88rs2000_read_status,
869 .read_ber = m88rs2000_read_ber,
870 .read_signal_strength = m88rs2000_read_signal_strength,
871 .read_snr = m88rs2000_read_snr,
872 .read_ucblocks = m88rs2000_read_ucblocks,
873 .diseqc_send_master_cmd = m88rs2000_send_diseqc_msg,
874 .diseqc_send_burst = m88rs2000_send_diseqc_burst,
875 .set_tone = m88rs2000_set_tone,
876 .set_voltage = m88rs2000_set_voltage,
878 .set_frontend = m88rs2000_set_frontend,
879 .get_frontend = m88rs2000_get_frontend,
899 if (m88rs2000_startup(state) < 0)