29 #define TDA10045_DEFAULT_FIRMWARE "dvb-fe-tda10045.fw"
30 #define TDA10046_DEFAULT_FIRMWARE "dvb-fe-tda10046.fw"
33 #include <linux/module.h>
34 #include <linux/device.h>
36 #include <linux/string.h>
37 #include <linux/slab.h>
43 #define dprintk(args...) \
45 if (debug) printk(KERN_DEBUG "tda1004x: " args); \
48 #define TDA1004X_CHIPID 0x00
49 #define TDA1004X_AUTO 0x01
50 #define TDA1004X_IN_CONF1 0x02
51 #define TDA1004X_IN_CONF2 0x03
52 #define TDA1004X_OUT_CONF1 0x04
53 #define TDA1004X_OUT_CONF2 0x05
54 #define TDA1004X_STATUS_CD 0x06
55 #define TDA1004X_CONFC4 0x07
56 #define TDA1004X_DSSPARE2 0x0C
57 #define TDA10045H_CODE_IN 0x0D
58 #define TDA10045H_FWPAGE 0x0E
59 #define TDA1004X_SCAN_CPT 0x10
60 #define TDA1004X_DSP_CMD 0x11
61 #define TDA1004X_DSP_ARG 0x12
62 #define TDA1004X_DSP_DATA1 0x13
63 #define TDA1004X_DSP_DATA2 0x14
64 #define TDA1004X_CONFADC1 0x15
65 #define TDA1004X_CONFC1 0x16
66 #define TDA10045H_S_AGC 0x1a
67 #define TDA10046H_AGC_TUN_LEVEL 0x1a
68 #define TDA1004X_SNR 0x1c
69 #define TDA1004X_CONF_TS1 0x1e
70 #define TDA1004X_CONF_TS2 0x1f
71 #define TDA1004X_CBER_RESET 0x20
72 #define TDA1004X_CBER_MSB 0x21
73 #define TDA1004X_CBER_LSB 0x22
74 #define TDA1004X_CVBER_LUT 0x23
75 #define TDA1004X_VBER_MSB 0x24
76 #define TDA1004X_VBER_MID 0x25
77 #define TDA1004X_VBER_LSB 0x26
78 #define TDA1004X_UNCOR 0x27
80 #define TDA10045H_CONFPLL_P 0x2D
81 #define TDA10045H_CONFPLL_M_MSB 0x2E
82 #define TDA10045H_CONFPLL_M_LSB 0x2F
83 #define TDA10045H_CONFPLL_N 0x30
85 #define TDA10046H_CONFPLL1 0x2D
86 #define TDA10046H_CONFPLL2 0x2F
87 #define TDA10046H_CONFPLL3 0x30
88 #define TDA10046H_TIME_WREF1 0x31
89 #define TDA10046H_TIME_WREF2 0x32
90 #define TDA10046H_TIME_WREF3 0x33
91 #define TDA10046H_TIME_WREF4 0x34
92 #define TDA10046H_TIME_WREF5 0x35
94 #define TDA10045H_UNSURW_MSB 0x31
95 #define TDA10045H_UNSURW_LSB 0x32
96 #define TDA10045H_WREF_MSB 0x33
97 #define TDA10045H_WREF_MID 0x34
98 #define TDA10045H_WREF_LSB 0x35
99 #define TDA10045H_MUXOUT 0x36
100 #define TDA1004X_CONFADC2 0x37
102 #define TDA10045H_IOFFSET 0x38
104 #define TDA10046H_CONF_TRISTATE1 0x3B
105 #define TDA10046H_CONF_TRISTATE2 0x3C
106 #define TDA10046H_CONF_POLARITY 0x3D
107 #define TDA10046H_FREQ_OFFSET 0x3E
108 #define TDA10046H_GPIO_OUT_SEL 0x41
109 #define TDA10046H_GPIO_SELECT 0x42
110 #define TDA10046H_AGC_CONF 0x43
111 #define TDA10046H_AGC_THR 0x44
112 #define TDA10046H_AGC_RENORM 0x45
113 #define TDA10046H_AGC_GAINS 0x46
114 #define TDA10046H_AGC_TUN_MIN 0x47
115 #define TDA10046H_AGC_TUN_MAX 0x48
116 #define TDA10046H_AGC_IF_MIN 0x49
117 #define TDA10046H_AGC_IF_MAX 0x4A
119 #define TDA10046H_FREQ_PHY2_MSB 0x4D
120 #define TDA10046H_FREQ_PHY2_LSB 0x4E
122 #define TDA10046H_CVBER_CTRL 0x4F
123 #define TDA10046H_AGC_IF_LEVEL 0x52
124 #define TDA10046H_CODE_CPT 0x57
125 #define TDA10046H_CODE_IN 0x58
134 dprintk(
"%s: reg=0x%x, data=0x%x\n", __func__, reg, data);
140 dprintk(
"%s: error reg=0x%x, data=0x%x, ret=%i\n",
141 __func__, reg, data, ret);
143 dprintk(
"%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__,
145 return (ret != 1) ? -1 : 0;
153 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
154 { .flags =
I2C_M_RD, .buf = b1, .len = 1 }};
156 dprintk(
"%s: reg=0x%x\n", __func__, reg);
163 dprintk(
"%s: error reg=0x%x, ret=%i\n", __func__, reg,
168 dprintk(
"%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__,
176 dprintk(
"%s: reg=0x%x, mask=0x%x, data=0x%x\n", __func__, reg,
180 val = tda1004x_read_byte(state, reg);
189 return tda1004x_write_byteI(state, reg, val);
192 static int tda1004x_write_buf(
struct tda1004x_state *state,
int reg,
unsigned char *
buf,
int len)
197 dprintk(
"%s: reg=0x%x, len=0x%x\n", __func__, reg, len);
200 for (i = 0; i <
len; i++) {
201 result = tda1004x_write_byteI(state, reg + i, buf[i]);
209 static int tda1004x_enable_tuner_i2c(
struct tda1004x_state *state)
219 static int tda1004x_disable_tuner_i2c(
struct tda1004x_state *state)
229 static u8 bandwidth_6mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x60, 0x1e, 0xa7, 0x45, 0x4f };
230 static u8 bandwidth_7mhz[] = { 0x02, 0x00, 0x37, 0x00, 0x4a, 0x2f, 0x6d, 0x76, 0xdb };
231 static u8 bandwidth_8mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x48, 0x17, 0x89, 0xc7, 0x14 };
258 static u8 bandwidth_6mhz_53M[] = { 0x7b, 0x2e, 0x11, 0xf0, 0xd2 };
259 static u8 bandwidth_7mhz_53M[] = { 0x6a, 0x02, 0x6a, 0x43, 0x9f };
260 static u8 bandwidth_8mhz_53M[] = { 0x5c, 0x32, 0xc2, 0x96, 0x6d };
262 static u8 bandwidth_6mhz_48M[] = { 0x70, 0x02, 0x49, 0x24, 0x92 };
263 static u8 bandwidth_7mhz_48M[] = { 0x60, 0x02, 0xaa, 0xaa, 0xab };
264 static u8 bandwidth_8mhz_48M[] = { 0x54, 0x03, 0x0c, 0x30, 0xc3 };
276 sizeof(bandwidth_6mhz_53M));
279 sizeof(bandwidth_6mhz_48M));
289 sizeof(bandwidth_7mhz_53M));
292 sizeof(bandwidth_7mhz_48M));
302 sizeof(bandwidth_8mhz_53M));
305 sizeof(bandwidth_8mhz_48M));
320 const unsigned char *
mem,
unsigned int len,
321 u8 dspCodeCounterReg,
u8 dspCodeInReg)
329 tda1004x_write_byteI(state, dspCodeCounterReg, 0);
333 buf[0] = dspCodeInReg;
341 memcpy(buf + 1, mem + pos, tx_size);
342 fw_msg.
len = tx_size + 1;
350 dprintk(
"%s: fw_pos=0x%x\n", __func__, pos);
383 if (data1 != 0x67 || data2 < 0x20 || data2 > 0x2e) {
384 printk(
KERN_INFO "tda1004x: found firmware revision %x -- invalid\n", data2);
387 printk(
KERN_INFO "tda1004x: found firmware revision %x -- ok\n", data2);
398 if (tda1004x_check_upload_ok(state) == 0)
405 printk(
KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
416 tda10045h_set_bandwidth(state, 8000000);
428 return tda1004x_check_upload_ok(state);
443 if(tda10046_clk53m) {
444 printk(
KERN_INFO "tda1004x: setting up plls for 53MHz sampling clock\n");
447 printk(
KERN_INFO "tda1004x: setting up plls for 48MHz sampling clock\n");
451 dprintk(
"%s: setting up PLLs for a 4 MHz Xtal\n", __func__);
454 dprintk(
"%s: setting up PLLs for a 16 MHz Xtal\n", __func__);
462 switch (state->
config->if_freq) {
480 tda10046h_set_bandwidth(state, 8000000);
495 dprintk(
"%s: 16MHz Xtal, reducing I2C speed\n", __func__);
510 tda10046_init_plls(fe);
514 if (tda1004x_check_upload_ok(state) == 0)
535 if (tda1004x_check_upload_ok(state) == 0)
540 if (state->
config->request_firmware !=
NULL) {
548 printk(
KERN_ERR "tda1004x: no firmware upload (timeout or file not found?)\n");
556 printk(
KERN_ERR "tda1004x: no request function defined, can't upload from file\n");
562 return tda1004x_check_upload_ok(state);
565 static int tda1004x_encode_fec(
int fec)
585 static int tda1004x_decode_fec(
int tdafec)
605 static int tda1004x_write(
struct dvb_frontend* fe,
const u8 buf[],
int len)
612 return tda1004x_write_byteI(state, buf[0], buf[1]);
621 if (tda10045_fwupload(fe)) {
622 printk(
"tda1004x: firmware upload failed\n");
641 tda1004x_write_mask(state, 0x1f, 0x01, state->
config->invert_oclk);
651 if (tda10046_fwupload(fe)) {
652 printk(
"tda1004x: firmware upload failed\n");
661 switch (state->
config->agc_config) {
681 if (state->
config->ts_mode == 0) {
683 tda1004x_write_mask(state, 0x3a, 0x80, state->
config->invert_oclk << 7);
687 state->
config->invert_oclk << 4);
724 if (fe->
ops.tuner_ops.set_params) {
725 fe->
ops.tuner_ops.set_params(fe);
726 if (fe->
ops.i2c_gate_ctrl)
727 fe->
ops.i2c_gate_ctrl(fe, 0);
806 tda10045h_set_bandwidth(state, fe_params->
bandwidth_hz);
810 tda10046h_set_bandwidth(state, fe_params->
bandwidth_hz);
816 if (state->
config->invert)
913 if (state->
config->invert)
1041 cber |= (status << 8);
1051 if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status &
FE_HAS_SYNC))) {
1059 vber |= (status << 8);
1063 vber |= (status & 0x0f) << 16;
1074 dprintk(
"%s: fe_status=0x%x\n", __func__, *fe_status);
1078 static int tda1004x_read_signal_strength(
struct dvb_frontend* fe,
u16 * signal)
1098 tmp = tda1004x_read_byte(state, reg);
1102 *signal = (tmp << 8) | tmp;
1103 dprintk(
"%s: signal=0x%x\n", __func__, *signal);
1120 *snr = ((tmp << 8) | tmp);
1121 dprintk(
"%s: snr=0x%x\n", __func__, *snr);
1125 static int tda1004x_read_ucblocks(
struct dvb_frontend* fe,
u32* ucblocks)
1140 while (counter++ < 5) {
1149 if ((tmp2 < tmp) || (tmp2 == 0))
1156 *ucblocks = 0xffffffff;
1158 dprintk(
"%s: ucblocks=0x%x\n", __func__, *ucblocks);
1181 dprintk(
"%s: ber=0x%x\n", __func__, *ber);
1199 gpio_conf = state->
config->gpio_config;
1202 (gpio_conf & 0x0f) ^ 0x0a);
1217 return tda1004x_enable_tuner_i2c(state);
1219 return tda1004x_disable_tuner_i2c(state);
1241 .name =
"Philips TDA10045H DVB-T",
1242 .frequency_min = 51000000,
1243 .frequency_max = 858000000,
1244 .frequency_stepsize = 166667,
1252 .release = tda1004x_release,
1254 .init = tda10045_init,
1255 .sleep = tda1004x_sleep,
1256 .write = tda1004x_write,
1257 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl,
1259 .set_frontend = tda1004x_set_fe,
1260 .get_frontend = tda1004x_get_fe,
1261 .get_tune_settings = tda1004x_get_tune_settings,
1263 .read_status = tda1004x_read_status,
1264 .read_ber = tda1004x_read_ber,
1265 .read_signal_strength = tda1004x_read_signal_strength,
1266 .read_snr = tda1004x_read_snr,
1267 .read_ucblocks = tda1004x_read_ucblocks,
1291 printk(
KERN_ERR "tda10045: chip is not answering. Giving up.\n");
1297 printk(
KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n",
id);
1311 .name =
"Philips TDA10046H DVB-T",
1312 .frequency_min = 51000000,
1313 .frequency_max = 858000000,
1314 .frequency_stepsize = 166667,
1322 .release = tda1004x_release,
1324 .init = tda10046_init,
1325 .sleep = tda1004x_sleep,
1326 .write = tda1004x_write,
1327 .i2c_gate_ctrl = tda1004x_i2c_gate_ctrl,
1329 .set_frontend = tda1004x_set_fe,
1330 .get_frontend = tda1004x_get_fe,
1331 .get_tune_settings = tda1004x_get_tune_settings,
1333 .read_status = tda1004x_read_status,
1334 .read_ber = tda1004x_read_ber,
1335 .read_signal_strength = tda1004x_read_signal_strength,
1336 .read_snr = tda1004x_read_snr,
1337 .read_ucblocks = tda1004x_read_ucblocks,
1361 printk(
KERN_ERR "tda10046: chip is not answering. Giving up.\n");
1366 printk(
KERN_ERR "Invalid tda1004x ID = 0x%02x. Can't proceed\n",
id);