19 #include <linux/kernel.h>
20 #include <asm/div64.h>
29 #define rc(args...) do { \
30 printk(KERN_ERR "mb86a20s: " args); \
33 #define dprintk(args...) \
36 printk(KERN_DEBUG "mb86a20s: %s: ", __func__); \
59 static struct regdata mb86a20s_init[] = {
64 { 0x50, 0xd1 }, { 0x51, 0x22 },
67 { 0x28, 0x2a }, { 0x29, 0x00 }, { 0x2a, 0xff }, { 0x2b, 0x80 },
68 { 0x28, 0x20 }, { 0x29, 0x33 }, { 0x2a, 0xdf }, { 0x2b, 0xa9 },
69 { 0x28, 0x22 }, { 0x29, 0x00 }, { 0x2a, 0x1f }, { 0x2b, 0xf0 },
73 { 0x04, 0x08 }, { 0x05, 0x05 },
74 { 0x04, 0x0e }, { 0x05, 0x00 },
75 { 0x04, 0x0f }, { 0x05, 0x14 },
76 { 0x04, 0x0b }, { 0x05, 0x8c },
77 { 0x04, 0x00 }, { 0x05, 0x00 },
78 { 0x04, 0x01 }, { 0x05, 0x07 },
79 { 0x04, 0x02 }, { 0x05, 0x0f },
80 { 0x04, 0x03 }, { 0x05, 0xa0 },
81 { 0x04, 0x09 }, { 0x05, 0x00 },
82 { 0x04, 0x0a }, { 0x05, 0xff },
83 { 0x04, 0x27 }, { 0x05, 0x64 },
84 { 0x04, 0x28 }, { 0x05, 0x00 },
85 { 0x04, 0x1e }, { 0x05, 0xff },
86 { 0x04, 0x29 }, { 0x05, 0x0a },
87 { 0x04, 0x32 }, { 0x05, 0x0a },
88 { 0x04, 0x14 }, { 0x05, 0x02 },
89 { 0x04, 0x04 }, { 0x05, 0x00 },
90 { 0x04, 0x05 }, { 0x05, 0x22 },
91 { 0x04, 0x06 }, { 0x05, 0x0e },
92 { 0x04, 0x07 }, { 0x05, 0xd8 },
93 { 0x04, 0x12 }, { 0x05, 0x00 },
94 { 0x04, 0x13 }, { 0x05, 0xff },
95 { 0x04, 0x15 }, { 0x05, 0x4e },
96 { 0x04, 0x16 }, { 0x05, 0x20 },
98 { 0x50, 0xa7 }, { 0x51, 0xff },
99 { 0x50, 0xa8 }, { 0x51, 0xff },
100 { 0x50, 0xa9 }, { 0x51, 0xff },
101 { 0x50, 0xaa }, { 0x51, 0xff },
102 { 0x50, 0xab }, { 0x51, 0xff },
103 { 0x50, 0xac }, { 0x51, 0xff },
104 { 0x50, 0xad }, { 0x51, 0xff },
105 { 0x50, 0xae }, { 0x51, 0xff },
106 { 0x50, 0xaf }, { 0x51, 0xff },
108 { 0x50, 0xdc }, { 0x51, 0x01 },
109 { 0x50, 0xdd }, { 0x51, 0xf4 },
110 { 0x50, 0xde }, { 0x51, 0x01 },
111 { 0x50, 0xdf }, { 0x51, 0xf4 },
112 { 0x50, 0xe0 }, { 0x51, 0x01 },
113 { 0x50, 0xe1 }, { 0x51, 0xf4 },
114 { 0x50, 0xb0 }, { 0x51, 0x07 },
115 { 0x50, 0xb2 }, { 0x51, 0xff },
116 { 0x50, 0xb3 }, { 0x51, 0xff },
117 { 0x50, 0xb4 }, { 0x51, 0xff },
118 { 0x50, 0xb5 }, { 0x51, 0xff },
119 { 0x50, 0xb6 }, { 0x51, 0xff },
120 { 0x50, 0xb7 }, { 0x51, 0xff },
121 { 0x50, 0x50 }, { 0x51, 0x02 },
122 { 0x50, 0x51 }, { 0x51, 0x04 },
125 { 0x50, 0xd5 }, { 0x51, 0x01 },
126 { 0x50, 0xd6 }, { 0x51, 0x1f },
127 { 0x50, 0xd2 }, { 0x51, 0x03 },
128 { 0x50, 0xd7 }, { 0x51, 0x3f },
129 { 0x28, 0x74 }, { 0x29, 0x00 }, { 0x28, 0x74 }, { 0x29, 0x40 },
130 { 0x28, 0x46 }, { 0x29, 0x2c }, { 0x28, 0x46 }, { 0x29, 0x0c },
131 { 0x04, 0x40 }, { 0x05, 0x01 },
132 { 0x28, 0x00 }, { 0x29, 0x10 },
133 { 0x28, 0x05 }, { 0x29, 0x02 },
135 { 0x28, 0x06 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x03 },
136 { 0x28, 0x07 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0d },
137 { 0x28, 0x08 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x02 },
138 { 0x28, 0x09 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x01 },
139 { 0x28, 0x0a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x21 },
140 { 0x28, 0x0b }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x29 },
141 { 0x28, 0x0c }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x16 },
142 { 0x28, 0x0d }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x31 },
143 { 0x28, 0x0e }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0e },
144 { 0x28, 0x0f }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x4e },
145 { 0x28, 0x10 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x46 },
146 { 0x28, 0x11 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x0f },
147 { 0x28, 0x12 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x56 },
148 { 0x28, 0x13 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x35 },
149 { 0x28, 0x14 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbe },
150 { 0x28, 0x15 }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0x84 },
151 { 0x28, 0x16 }, { 0x29, 0x00 }, { 0x2a, 0x03 }, { 0x2b, 0xee },
152 { 0x28, 0x17 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x98 },
153 { 0x28, 0x18 }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x9f },
154 { 0x28, 0x19 }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0xb2 },
155 { 0x28, 0x1a }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0xc2 },
156 { 0x28, 0x1b }, { 0x29, 0x00 }, { 0x2a, 0x07 }, { 0x2b, 0x4a },
157 { 0x28, 0x1c }, { 0x29, 0x00 }, { 0x2a, 0x01 }, { 0x2b, 0xbc },
158 { 0x28, 0x1d }, { 0x29, 0x00 }, { 0x2a, 0x04 }, { 0x2b, 0xba },
159 { 0x28, 0x1e }, { 0x29, 0x00 }, { 0x2a, 0x06 }, { 0x2b, 0x14 },
160 { 0x50, 0x1e }, { 0x51, 0x5d },
161 { 0x50, 0x22 }, { 0x51, 0x00 },
162 { 0x50, 0x23 }, { 0x51, 0xc8 },
163 { 0x50, 0x24 }, { 0x51, 0x00 },
164 { 0x50, 0x25 }, { 0x51, 0xf0 },
165 { 0x50, 0x26 }, { 0x51, 0x00 },
166 { 0x50, 0x27 }, { 0x51, 0xc3 },
167 { 0x50, 0x39 }, { 0x51, 0x02 },
168 { 0x28, 0x6a }, { 0x29, 0x00 }, { 0x2a, 0x00 }, { 0x2b, 0x00 },
172 static struct regdata mb86a20s_reset_reception[] = {
184 .addr = i2c_addr, .flags = 0, .buf =
buf, .len = 2
190 printk(
"%s: writereg error (rc == %i, reg == 0x%02x,"
191 " data == 0x%02x)\n", __func__, rc, reg, data);
198 static int mb86a20s_i2c_writeregdata(
struct mb86a20s_state *state,
203 for (i = 0; i <
size; i++) {
204 rc = mb86a20s_i2c_writereg(state, i2c_addr, rd[i].reg,
218 { .
addr = i2c_addr, .flags = 0, .buf = &
reg, .len = 1 },
219 { .addr = i2c_addr, .flags =
I2C_M_RD, .buf = &
val, .len = 1 }
225 rc(
"%s: reg=0x%x (error=%d)\n", __func__, reg, rc);
232 #define mb86a20s_readreg(state, reg) \
233 mb86a20s_i2c_readreg(state, state->config->demod_address, reg)
234 #define mb86a20s_writereg(state, reg, val) \
235 mb86a20s_i2c_writereg(state, state->config->demod_address, reg, val)
236 #define mb86a20s_writeregdata(state, regdata) \
237 mb86a20s_i2c_writeregdata(state, state->config->demod_address, \
238 regdata, ARRAY_SIZE(regdata))
248 if (fe->
ops.i2c_gate_ctrl)
249 fe->
ops.i2c_gate_ctrl(fe, 0);
256 if (!state->
config->is_serial) {
267 if (fe->
ops.i2c_gate_ctrl)
268 fe->
ops.i2c_gate_ctrl(fe, 1);
276 dprintk(
"Initialization succeeded.\n");
281 static int mb86a20s_read_signal_strength(
struct dvb_frontend *fe,
u16 *strength)
284 unsigned rf_max, rf_min, rf;
289 if (fe->
ops.i2c_gate_ctrl)
290 fe->
ops.i2c_gate_ctrl(fe, 0);
296 rf = (rf_max + rf_min) / 2;
304 rf_min = (rf_max + rf_min) / 2;
306 rf_max = (rf_max + rf_min) / 2;
307 if (rf_max - rf_min < 4) {
308 *strength = (((rf_max + rf_min) / 2) * 65535) / 4095;
313 dprintk(
"signal strength = %d\n", *strength);
315 if (fe->
ops.i2c_gate_ctrl)
316 fe->
ops.i2c_gate_ctrl(fe, 1);
329 if (fe->
ops.i2c_gate_ctrl)
330 fe->
ops.i2c_gate_ctrl(fe, 0);
332 if (fe->
ops.i2c_gate_ctrl)
333 fe->
ops.i2c_gate_ctrl(fe, 1);
350 dprintk(
"val = %d, status = 0x%02x\n", val, *status);
355 static int mb86a20s_set_frontend(
struct dvb_frontend *fe)
368 if (fe->
ops.i2c_gate_ctrl)
369 fe->
ops.i2c_gate_ctrl(fe, 1);
370 dprintk(
"Calling tuner set parameters\n");
371 fe->
ops.tuner_ops.set_params(fe);
386 if (fe->
ops.i2c_gate_ctrl)
387 fe->
ops.i2c_gate_ctrl(fe, 0);
389 if (fe->
ops.i2c_gate_ctrl)
390 fe->
ops.i2c_gate_ctrl(fe, 1);
399 static unsigned char reg[] = {
413 switch ((rc & 0x70) >> 4) {
432 static unsigned char reg[] = {
462 static int mb86a20s_get_interleaving(
struct mb86a20s_state *state,
467 static unsigned char reg[] = {
486 static int mb86a20s_get_segment_count(
struct mb86a20s_state *state,
491 static unsigned char reg[] = {
505 count = (rc >> 4) & 0x0f;
510 static int mb86a20s_get_frontend(
struct dvb_frontend *fe)
520 if (fe->
ops.i2c_gate_ctrl)
521 fe->
ops.i2c_gate_ctrl(fe, 0);
532 for (i = 0; i < 3; i++) {
533 rc = mb86a20s_get_segment_count(state, i);
534 if (rc >= 0 && rc < 14)
539 rc = mb86a20s_get_modulation(state, i);
542 rc = mb86a20s_get_fec(state, i);
545 rc = mb86a20s_get_interleaving(state, i);
552 if ((rc >= 0) && ((rc & 0x60) == 0x20)) {
565 if ((rc & 0x60) == 0x20) {
566 switch (rc & 0x0c >> 2) {
593 if (fe->
ops.i2c_gate_ctrl)
594 fe->
ops.i2c_gate_ctrl(fe, 1);
601 unsigned int mode_flags,
610 rc = mb86a20s_set_frontend(fe);
613 mb86a20s_read_status(fe, status);
640 rc(
"Unable to kzalloc\n");
676 .name =
"Fujitsu mb86A20s",
684 .frequency_min = 45000000,
685 .frequency_max = 864000000,
686 .frequency_stepsize = 62500,
689 .release = mb86a20s_release,
691 .init = mb86a20s_initfe,
692 .set_frontend = mb86a20s_set_frontend,
693 .get_frontend = mb86a20s_get_frontend,
694 .read_status = mb86a20s_read_status,
695 .read_signal_strength = mb86a20s_read_signal_strength,
696 .tune = mb86a20s_tune,