25 #include <linux/errno.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/string.h>
30 #include <linux/slab.h>
48 #define dprintk(x...) printk(x)
55 #define XIN 57840000UL
57 #define FIN (XIN >> 4)
59 static int tda10021_inittab_size = 0x40;
60 static u8 tda10021_inittab[0x40]=
62 0x73, 0x6a, 0x23, 0x0a, 0x02, 0x37, 0x77, 0x1a,
63 0x37, 0x6a, 0x17, 0x8a, 0x1e, 0x86, 0x43, 0x40,
64 0xb8, 0x3f, 0xa1, 0x00, 0xcd, 0x01, 0x00, 0xff,
65 0x11, 0x00, 0x7c, 0x31, 0x30, 0x20, 0x00, 0x00,
66 0x02, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, 0x00,
67 0x07, 0x00, 0x33, 0x11, 0x0d, 0x95, 0x08, 0x58,
68 0x00, 0x00, 0x80, 0x00, 0x80, 0xff, 0x00, 0x00,
69 0x04, 0x2d, 0x2f, 0xff, 0x00, 0x00, 0x00, 0x00,
75 struct i2c_msg msg = { .addr = state->
config->demod_address, .flags = 0, .buf =
buf, .len = 2 };
80 printk(
"DVB: TDA10021(%d): %s, writereg error "
81 "(reg == 0x%02x, val == 0x%02x, ret == %i)\n",
82 state->
frontend.dvb->num, __func__, reg, data, ret);
92 struct i2c_msg msg [] = { { .
addr = state->
config->demod_address, .flags = 0, .buf = b0, .len = 1 },
93 { .addr = state->
config->demod_address, .flags =
I2C_M_RD, .buf = b1, .len = 1 } };
98 if (ret != 2 && reg != 0x1a)
99 printk(
"DVB: TDA10021: %s: readreg error (ret == %i)\n",
107 u8 buf[2] = { 0x0f, tda10021_inittab[0x0f] | 0x80 };
112 printk(
"tda10021: lock tuner fails\n");
121 u8 buf[2] = { 0x0f, tda10021_inittab[0x0f] & 0x7f };
126 printk(
"tda10021: unlock tuner fails\n");
135 reg0 |= state->
reg0 & 0x63;
142 _tda10021_writereg (state, 0x00, reg0 & 0xfe);
143 _tda10021_writereg (state, 0x00, reg0 | 0x01);
149 static int tda10021_set_symbolrate (
struct tda10021_state* state,
u32 symbolrate)
157 if (symbolrate >
XIN/2)
159 if (symbolrate < 500000)
162 if (symbolrate <
XIN/16) NDEC = 1;
163 if (symbolrate <
XIN/32) NDEC = 2;
164 if (symbolrate <
XIN/64) NDEC = 3;
166 if (symbolrate < (
u32)(
XIN/12.3)) SFIL = 1;
167 if (symbolrate < (
u32)(
XIN/16)) SFIL = 0;
168 if (symbolrate < (
u32)(
XIN/24.6)) SFIL = 1;
169 if (symbolrate < (
u32)(
XIN/32)) SFIL = 0;
170 if (symbolrate < (
u32)(
XIN/49.2)) SFIL = 1;
171 if (symbolrate < (
u32)(
XIN/64)) SFIL = 0;
172 if (symbolrate < (
u32)(
XIN/98.4)) SFIL = 1;
175 ratio = (symbolrate << 4) /
FIN;
176 tmp = ((symbolrate << 4) %
FIN) << 8;
177 ratio = (ratio << 8) + tmp /
FIN;
178 tmp = (tmp %
FIN) << 8;
182 BDRI = (((
XIN << 5) / symbolrate) + 1) / 2;
187 SFIL = (SFIL << 4) | tda10021_inittab[0x0E];
189 NDEC = (NDEC << 6) | tda10021_inittab[0x03];
191 _tda10021_writereg (state, 0x03, NDEC);
192 _tda10021_writereg (state, 0x0a, BDR&0xff);
193 _tda10021_writereg (state, 0x0b, (BDR>> 8)&0xff);
194 _tda10021_writereg (state, 0x0c, (BDR>>16)&0x3f);
196 _tda10021_writereg (state, 0x0d, BDRI);
197 _tda10021_writereg (state, 0x0e, SFIL);
207 dprintk(
"DVB: TDA10021(%d): init chip\n", fe->adapter->num);
211 for (i=0; i<tda10021_inittab_size; i++)
212 _tda10021_writereg (state, i, tda10021_inittab[i]);
214 _tda10021_writereg (state, 0x34, state->
pwm);
223 _tda10021_writereg(state, 0x2a, tda10021_inittab[0x2a] & 0xef);
231 static int tda10021_set_parameters(
struct dvb_frontend *fe)
239 static const struct qam_params qam_params[] = {
241 [
QPSK] = { 0x14, 0x78, 0x78, 0x8c, 0x96 },
242 [
QAM_16] = { 0x00, 0x8c, 0x87, 0xa2, 0x91 },
243 [
QAM_32] = { 0x04, 0x8c, 0x64, 0x74, 0x96 },
244 [
QAM_64] = { 0x08, 0x6a, 0x46, 0x43, 0x6a },
245 [
QAM_128] = { 0x0c, 0x78, 0x36, 0x34, 0x7e },
246 [
QAM_256] = { 0x10, 0x5c, 0x26, 0x23, 0x6b },
284 if (fe->
ops.tuner_ops.set_params) {
285 fe->
ops.tuner_ops.set_params(fe);
286 if (fe->
ops.i2c_gate_ctrl) fe->
ops.i2c_gate_ctrl(fe, 0);
290 _tda10021_writereg(state, 0x34, state->
pwm);
292 _tda10021_writereg(state, 0x01, qam_params[qam].
agcref);
293 _tda10021_writereg(state, 0x05, qam_params[qam].
lthr);
294 _tda10021_writereg(state, 0x08, qam_params[qam].
mseth);
295 _tda10021_writereg(state, 0x09, qam_params[qam].
aref);
301 reg0x3d = tda10021_readreg (state, 0x3d);
303 _tda10021_writereg (state, 0x3d, 0x01 | reg0x3d);
305 _tda10021_writereg (state, 0x3d, 0xfe & reg0x3d);
306 tda10021_setup_reg0(state, qam_params[qam].
conf, c->
inversion);
322 sync = tda10021_readreg (state, 0x11);
340 u32 _ber = tda10021_readreg(state, 0x14) |
341 (tda10021_readreg(state, 0x15) << 8) |
342 ((tda10021_readreg(state, 0x16) & 0x0f) << 16);
343 _tda10021_writereg(state, 0x10, (tda10021_readreg(state, 0x10) & ~0xc0)
344 | (tda10021_inittab[0x10] & 0xc0));
350 static int tda10021_read_signal_strength(
struct dvb_frontend* fe,
u16* strength)
354 u8 config = tda10021_readreg(state, 0x02);
355 u8 gain = tda10021_readreg(state, 0x17);
359 *strength = (gain << 8) | gain;
368 u8 quality = ~tda10021_readreg(state, 0x18);
369 *snr = (quality << 8) | quality;
374 static int tda10021_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
378 *ucblocks = tda10021_readreg (state, 0x13) & 0x7f;
379 if (*ucblocks == 0x7f)
380 *ucblocks = 0xffffffff;
383 _tda10021_writereg (state, 0x10, tda10021_inittab[0x10] & 0xdf);
384 _tda10021_writereg (state, 0x10, tda10021_inittab[0x10]);
389 static int tda10021_get_frontend(
struct dvb_frontend *fe)
396 sync = tda10021_readreg(state, 0x11);
397 afc = tda10021_readreg(state, 0x19);
400 printk(sync & 2 ?
"DVB: TDA10021(%d): AFC (%d) %dHz\n" :
401 "DVB: TDA10021(%d): [AFC (%d) %dHz]\n",
434 _tda10021_writereg (state, 0x1b, 0x02);
435 _tda10021_writereg (state, 0x00, 0x80);
463 state->
reg0 = tda10021_inittab[0];
466 id = tda10021_readreg(state, 0x1a);
467 if ((
id & 0xf0) != 0x70)
goto error;
473 printk(
"TDA10021: i2c-addr = 0x%02x, id = 0x%02x\n",
474 state->
config->demod_address,
id);
489 .name =
"Philips TDA10021 DVB-C",
490 .frequency_stepsize = 62500,
491 .frequency_min = 47000000,
492 .frequency_max = 862000000,
493 .symbol_rate_min = (
XIN/2)/64,
494 .symbol_rate_max = (
XIN/2)/4,
496 .frequency_tolerance = ???,
497 .symbol_rate_tolerance = ???,
505 .release = tda10021_release,
507 .init = tda10021_init,
508 .sleep = tda10021_sleep,
509 .i2c_gate_ctrl = tda10021_i2c_gate_ctrl,
511 .set_frontend = tda10021_set_parameters,
512 .get_frontend = tda10021_get_frontend,
514 .read_status = tda10021_read_status,
515 .read_ber = tda10021_read_ber,
516 .read_signal_strength = tda10021_read_signal_strength,
517 .read_snr = tda10021_read_snr,
518 .read_ucblocks = tda10021_read_ucblocks,
525 MODULE_AUTHOR(
"Ralph Metzler, Holger Waechtler, Markus Schulz");