2 Driver for Philips tda1004xh OFDM Frontend
4 (c) 2003, 2004 Andrew de Quincey & Robert Schlabbach
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 This driver needs a copy of the DLL "ttlcdacc.dll" from the Haupauge or Technotrend
25 windows driver saved as '/usr/lib/hotplug/firmware/tda1004x.bin'.
26 You can also pass the complete file name with the module parameter 'tda1004x_firmware'.
28 Currently the DLL from v2.15a of the technotrend driver is supported. Other versions can
29 be added reasonably painlessly.
31 Windows driver URL: http://www.technotrend.de/
35 #include <linux/kernel.h>
36 #include <linux/vmalloc.h>
37 #include <linux/module.h>
38 #include <linux/init.h>
39 #include <linux/string.h>
40 #include <linux/slab.h>
42 #include <linux/fcntl.h>
43 #include <linux/errno.h>
44 #include <linux/syscalls.h>
46 #include "dvb_frontend.h"
47 #include "dvb_functions.h"
49 #ifndef DVB_TDA1004X_FIRMWARE_FILE
50 #define DVB_TDA1004X_FIRMWARE_FILE "/usr/lib/hotplug/firmware/tda1004x.bin"
53 static int tda1004x_debug = 0;
54 static char *tda1004x_firmware = DVB_TDA1004X_FIRMWARE_FILE;
56 #define MC44BC374_ADDRESS 0x65
58 #define TDA1004X_CHIPID 0x00
59 #define TDA1004X_AUTO 0x01
60 #define TDA1004X_IN_CONF1 0x02
61 #define TDA1004X_IN_CONF2 0x03
62 #define TDA1004X_OUT_CONF1 0x04
63 #define TDA1004X_OUT_CONF2 0x05
64 #define TDA1004X_STATUS_CD 0x06
65 #define TDA1004X_CONFC4 0x07
66 #define TDA1004X_DSSPARE2 0x0C
67 #define TDA10045H_CODE_IN 0x0D
68 #define TDA10045H_FWPAGE 0x0E
69 #define TDA1004X_SCAN_CPT 0x10
70 #define TDA1004X_DSP_CMD 0x11
71 #define TDA1004X_DSP_ARG 0x12
72 #define TDA1004X_DSP_DATA1 0x13
73 #define TDA1004X_DSP_DATA2 0x14
74 #define TDA1004X_CONFADC1 0x15
75 #define TDA1004X_CONFC1 0x16
76 #define TDA10045H_S_AGC 0x1a
77 #define TDA10046H_AGC_TUN_LEVEL 0x1a
78 #define TDA1004X_SNR 0x1c
79 #define TDA1004X_CONF_TS1 0x1e
80 #define TDA1004X_CONF_TS2 0x1f
81 #define TDA1004X_CBER_RESET 0x20
82 #define TDA1004X_CBER_MSB 0x21
83 #define TDA1004X_CBER_LSB 0x22
84 #define TDA1004X_CVBER_LUT 0x23
85 #define TDA1004X_VBER_MSB 0x24
86 #define TDA1004X_VBER_MID 0x25
87 #define TDA1004X_VBER_LSB 0x26
88 #define TDA1004X_UNCOR 0x27
90 #define TDA10045H_CONFPLL_P 0x2D
91 #define TDA10045H_CONFPLL_M_MSB 0x2E
92 #define TDA10045H_CONFPLL_M_LSB 0x2F
93 #define TDA10045H_CONFPLL_N 0x30
95 #define TDA10046H_CONFPLL1 0x2D
96 #define TDA10046H_CONFPLL2 0x2F
97 #define TDA10046H_CONFPLL3 0x30
98 #define TDA10046H_TIME_WREF1 0x31
99 #define TDA10046H_TIME_WREF2 0x32
100 #define TDA10046H_TIME_WREF3 0x33
101 #define TDA10046H_TIME_WREF4 0x34
102 #define TDA10046H_TIME_WREF5 0x35
104 #define TDA10045H_UNSURW_MSB 0x31
105 #define TDA10045H_UNSURW_LSB 0x32
106 #define TDA10045H_WREF_MSB 0x33
107 #define TDA10045H_WREF_MID 0x34
108 #define TDA10045H_WREF_LSB 0x35
109 #define TDA10045H_MUXOUT 0x36
110 #define TDA1004X_CONFADC2 0x37
112 #define TDA10045H_IOFFSET 0x38
114 #define TDA10046H_CONF_TRISTATE1 0x3B
115 #define TDA10046H_CONF_TRISTATE2 0x3C
116 #define TDA10046H_CONF_POLARITY 0x3D
117 #define TDA10046H_FREQ_OFFSET 0x3E
118 #define TDA10046H_GPIO_OUT_SEL 0x41
119 #define TDA10046H_GPIO_SELECT 0x42
120 #define TDA10046H_AGC_CONF 0x43
121 #define TDA10046H_AGC_GAINS 0x46
122 #define TDA10046H_AGC_TUN_MIN 0x47
123 #define TDA10046H_AGC_TUN_MAX 0x48
124 #define TDA10046H_AGC_IF_MIN 0x49
125 #define TDA10046H_AGC_IF_MAX 0x4A
127 #define TDA10046H_FREQ_PHY2_MSB 0x4D
128 #define TDA10046H_FREQ_PHY2_LSB 0x4E
130 #define TDA10046H_CVBER_CTRL 0x4F
131 #define TDA10046H_AGC_IF_LEVEL 0x52
132 #define TDA10046H_CODE_CPT 0x57
133 #define TDA10046H_CODE_IN 0x58
136 #define FE_TYPE_TDA10045H 0
137 #define FE_TYPE_TDA10046H 1
139 #define TUNER_TYPE_TD1344 0
140 #define TUNER_TYPE_TD1316 1
142 #define dprintk if (tda1004x_debug) printk
144 static struct dvb_frontend_info tda10045h_info = {
145 .name = "Philips TDA10045H",
147 .frequency_min = 51000000,
148 .frequency_max = 858000000,
149 .frequency_stepsize = 166667,
151 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
152 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
153 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
154 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
157 static struct dvb_frontend_info tda10046h_info = {
158 .name = "Philips TDA10046H",
160 .frequency_min = 51000000,
161 .frequency_max = 858000000,
162 .frequency_stepsize = 166667,
164 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
165 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
166 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
167 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO
171 struct tda1004x_state {
185 static struct fwinfo tda10045h_fwinfo[] = { {.file_size = 286720,.fw_offset = 0x34cc5,.fw_size = 30555} };
186 static int tda10045h_fwinfo_count = sizeof(tda10045h_fwinfo) / sizeof(struct fwinfo);
188 static struct fwinfo tda10046h_fwinfo[] = { {.file_size = 286720,.fw_offset = 0x3c4f9,.fw_size = 24479} };
189 static int tda10046h_fwinfo_count = sizeof(tda10046h_fwinfo) / sizeof(struct fwinfo);
194 static int tda1004x_write_byte(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state, int reg, int data)
197 u8 buf[] = { reg, data };
198 struct i2c_msg msg = { .addr=0, .flags=0, .buf=buf, .len=2 };
200 dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data);
202 msg.addr = tda_state->tda1004x_address;
203 ret = i2c->xfer(i2c, &msg, 1);
206 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
207 __FUNCTION__, reg, data, ret);
209 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__,
211 return (ret != 1) ? -1 : 0;
214 static int tda1004x_read_byte(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state, int reg)
219 struct i2c_msg msg[] = {{ .addr=0, .flags=0, .buf=b0, .len=1},
220 { .addr=0, .flags=I2C_M_RD, .buf=b1, .len = 1}};
222 dprintk("%s: reg=0x%x\n", __FUNCTION__, reg);
224 msg[0].addr = tda_state->tda1004x_address;
225 msg[1].addr = tda_state->tda1004x_address;
226 ret = i2c->xfer(i2c, msg, 2);
229 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg,
234 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__,
239 static int tda1004x_write_mask(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state, int reg, int mask, int data)
242 dprintk("%s: reg=0x%x, mask=0x%x, data=0x%x\n", __FUNCTION__, reg,
245 // read a byte and check
246 val = tda1004x_read_byte(i2c, tda_state, reg);
254 // write it out again
255 return tda1004x_write_byte(i2c, tda_state, reg, val);
258 static int tda1004x_write_buf(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state, int reg, unsigned char *buf, int len)
263 dprintk("%s: reg=0x%x, len=0x%x\n", __FUNCTION__, reg, len);
266 for (i = 0; i < len; i++) {
267 result = tda1004x_write_byte(i2c, tda_state, reg + i, buf[i]);
275 static int tda1004x_enable_tuner_i2c(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state)
278 dprintk("%s\n", __FUNCTION__);
280 result = tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 2, 2);
285 static int tda1004x_disable_tuner_i2c(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state)
288 dprintk("%s\n", __FUNCTION__);
290 return tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 2, 0);
294 static int tda10045h_set_bandwidth(struct dvb_i2c_bus *i2c,
295 struct tda1004x_state *tda_state,
296 fe_bandwidth_t bandwidth)
298 static u8 bandwidth_6mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x60, 0x1e, 0xa7, 0x45, 0x4f };
299 static u8 bandwidth_7mhz[] = { 0x02, 0x00, 0x37, 0x00, 0x4a, 0x2f, 0x6d, 0x76, 0xdb };
300 static u8 bandwidth_8mhz[] = { 0x02, 0x00, 0x3d, 0x00, 0x48, 0x17, 0x89, 0xc7, 0x14 };
303 case BANDWIDTH_6_MHZ:
304 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0x14);
305 tda1004x_write_buf(i2c, tda_state, TDA10045H_CONFPLL_P, bandwidth_6mhz, sizeof(bandwidth_6mhz));
308 case BANDWIDTH_7_MHZ:
309 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0x80);
310 tda1004x_write_buf(i2c, tda_state, TDA10045H_CONFPLL_P, bandwidth_7mhz, sizeof(bandwidth_7mhz));
313 case BANDWIDTH_8_MHZ:
314 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0x14);
315 tda1004x_write_buf(i2c, tda_state, TDA10045H_CONFPLL_P, bandwidth_8mhz, sizeof(bandwidth_8mhz));
322 tda1004x_write_byte(i2c, tda_state, TDA10045H_IOFFSET, 0);
329 static int tda10046h_set_bandwidth(struct dvb_i2c_bus *i2c,
330 struct tda1004x_state *tda_state,
331 fe_bandwidth_t bandwidth)
333 static u8 bandwidth_6mhz[] = { 0x80, 0x15, 0xfe, 0xab, 0x8e };
334 static u8 bandwidth_7mhz[] = { 0x6e, 0x02, 0x53, 0xc8, 0x25 };
335 static u8 bandwidth_8mhz[] = { 0x60, 0x12, 0xa8, 0xe4, 0xbd };
338 case BANDWIDTH_6_MHZ:
339 tda1004x_write_buf(i2c, tda_state, TDA10046H_TIME_WREF1, bandwidth_6mhz, sizeof(bandwidth_6mhz));
340 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0);
343 case BANDWIDTH_7_MHZ:
344 tda1004x_write_buf(i2c, tda_state, TDA10046H_TIME_WREF1, bandwidth_7mhz, sizeof(bandwidth_7mhz));
345 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0);
348 case BANDWIDTH_8_MHZ:
349 tda1004x_write_buf(i2c, tda_state, TDA10046H_TIME_WREF1, bandwidth_8mhz, sizeof(bandwidth_8mhz));
350 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSSPARE2, 0xFF);
362 static int tda1004x_fwupload(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state)
365 struct i2c_msg fw_msg = {.addr = 0,.flags = 0,.buf = fw_buf,.len = 0 };
366 unsigned char *firmware = NULL;
371 int fw_pos, fw_offset;
373 mm_segment_t fs = get_fs();
374 int dspCodeCounterReg=0, dspCodeInReg=0, dspVersion=0;
376 struct fwinfo* fwInfo = NULL;
377 unsigned long timeout;
380 switch(tda_state->fe_type) {
381 case FE_TYPE_TDA10045H:
382 dspCodeCounterReg = TDA10045H_FWPAGE;
383 dspCodeInReg = TDA10045H_CODE_IN;
385 fwInfoCount = tda10045h_fwinfo_count;
386 fwInfo = tda10045h_fwinfo;
389 case FE_TYPE_TDA10046H:
390 dspCodeCounterReg = TDA10046H_CODE_CPT;
391 dspCodeInReg = TDA10046H_CODE_IN;
393 fwInfoCount = tda10046h_fwinfo_count;
394 fwInfo = tda10046h_fwinfo;
400 fd = sys_open(tda1004x_firmware, 0, 0);
402 printk("%s: Unable to open firmware %s\n", __FUNCTION__,
406 filesize = sys_lseek(fd, 0L, 2);
408 printk("%s: Firmware %s is empty\n", __FUNCTION__,
414 // find extraction parameters for firmware
415 for (fwinfo_idx = 0; fwinfo_idx < fwInfoCount; fwinfo_idx++) {
416 if (fwInfo[fwinfo_idx].file_size == filesize)
419 if (fwinfo_idx >= fwInfoCount) {
420 printk("%s: Unsupported firmware %s\n", __FUNCTION__, tda1004x_firmware);
424 fw_size = fwInfo[fwinfo_idx].fw_size;
425 fw_offset = fwInfo[fwinfo_idx].fw_offset;
427 // allocate buffer for it
428 firmware = vmalloc(fw_size);
429 if (firmware == NULL) {
430 printk("%s: Out of memory loading firmware\n",
437 sys_lseek(fd, fw_offset, 0);
438 if (sys_read(fd, firmware, fw_size) != fw_size) {
439 printk("%s: Failed to read firmware\n", __FUNCTION__);
447 // set some valid bandwith parameters before uploading
448 switch(tda_state->fe_type) {
449 case FE_TYPE_TDA10045H:
451 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 0x10, 0);
452 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 8, 8);
453 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 8, 0);
457 tda10045h_set_bandwidth(i2c, tda_state, BANDWIDTH_8_MHZ);
460 case FE_TYPE_TDA10046H:
462 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 1, 0);
463 tda1004x_write_mask(i2c, tda_state, TDA10046H_CONF_TRISTATE1, 1, 0);
467 tda1004x_write_byte(i2c, tda_state, TDA10046H_CONFPLL2, 10);
468 tda1004x_write_byte(i2c, tda_state, TDA10046H_CONFPLL3, 0);
469 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_OFFSET, 99);
470 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_PHY2_MSB, 0xd4);
471 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_PHY2_LSB, 0x2c);
472 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 8, 8); // going to boot from HOST
476 // do the firmware upload
477 tda1004x_write_byte(i2c, tda_state, dspCodeCounterReg, 0); // clear code counter
478 fw_msg.addr = tda_state->tda1004x_address;
480 while (fw_pos != fw_size) {
482 // work out how much to send this time
483 tx_size = fw_size - fw_pos;
484 if (tx_size > 0x10) {
489 fw_buf[0] = dspCodeInReg;
490 memcpy(fw_buf + 1, firmware + fw_pos, tx_size);
491 fw_msg.len = tx_size + 1;
492 if (i2c->xfer(i2c, &fw_msg, 1) != 1) {
493 printk("tda1004x: Error during firmware upload\n");
499 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, fw_pos);
503 // wait for DSP to initialise
504 switch(tda_state->fe_type) {
505 case FE_TYPE_TDA10045H:
506 // DSPREADY doesn't seem to work on the TDA10045H
510 case FE_TYPE_TDA10046H:
511 timeout = jiffies + HZ;
512 while(!(tda1004x_read_byte(i2c, tda_state, TDA1004X_STATUS_CD) & 0x20)) {
513 if (time_after(jiffies, timeout)) {
514 printk("tda1004x: DSP failed to initialised.\n");
523 // check upload was OK
524 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 0x10, 0); // we want to read from the DSP
525 tda1004x_write_byte(i2c, tda_state, TDA1004X_DSP_CMD, 0x67);
526 if ((tda1004x_read_byte(i2c, tda_state, TDA1004X_DSP_DATA1) != 0x67) ||
527 (tda1004x_read_byte(i2c, tda_state, TDA1004X_DSP_DATA2) != dspVersion)) {
528 printk("%s: firmware upload failed!\n", __FUNCTION__);
537 static int tda10045h_init(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state)
539 struct i2c_msg tuner_msg = {.addr = 0,.flags = 0,.buf = NULL,.len = 0 };
540 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
542 dprintk("%s\n", __FUNCTION__);
544 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFADC1, 0x10, 0); // wake up the ADC
546 // Disable the MC44BC374C
547 tda1004x_enable_tuner_i2c(i2c, tda_state);
548 tuner_msg.addr = MC44BC374_ADDRESS;
549 tuner_msg.buf = disable_mc44BC374c;
550 tuner_msg.len = sizeof(disable_mc44BC374c);
551 if (i2c->xfer(i2c, &tuner_msg, 1) != 1) {
552 i2c->xfer(i2c, &tuner_msg, 1);
554 tda1004x_disable_tuner_i2c(i2c, tda_state);
557 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
558 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 8, 0); // select HP stream
559 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x40, 0); // no frequency inversion
560 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x80, 0x80); // enable pulse killer
561 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 0x10, 0x10); // enable auto offset
562 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF2, 0xC0, 0x0); // no frequency offset
563 tda1004x_write_byte(i2c, tda_state, TDA1004X_CONF_TS1, 0); // setup MPEG2 TS interface
564 tda1004x_write_byte(i2c, tda_state, TDA1004X_CONF_TS2, 0); // setup MPEG2 TS interface
565 tda1004x_write_mask(i2c, tda_state, TDA1004X_VBER_MSB, 0xe0, 0xa0); // 10^6 VBER measurement bits
566 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x10, 0); // VAGC polarity
567 tda1004x_write_byte(i2c, tda_state, TDA1004X_CONFADC1, 0x2e);
575 static int tda10046h_init(struct dvb_i2c_bus *i2c, struct tda1004x_state *tda_state)
577 struct i2c_msg tuner_msg = {.addr = 0,.flags = 0,.buf = NULL,.len = 0 };
578 static u8 disable_mc44BC374c[] = { 0x1d, 0x74, 0xa0, 0x68 };
580 dprintk("%s\n", __FUNCTION__);
582 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 1, 0); // wake up the chip
584 // Disable the MC44BC374C
585 tda1004x_enable_tuner_i2c(i2c, tda_state);
586 tuner_msg.addr = MC44BC374_ADDRESS;
587 tuner_msg.buf = disable_mc44BC374c;
588 tuner_msg.len = sizeof(disable_mc44BC374c);
589 if (i2c->xfer(i2c, &tuner_msg, 1) != 1) {
590 i2c->xfer(i2c, &tuner_msg, 1);
592 tda1004x_disable_tuner_i2c(i2c, tda_state);
595 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 0x20, 0); // disable DSP watchdog timer
596 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x40, 0x40); // TT TDA10046H needs inversion ON
597 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 8, 0); // select HP stream
598 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x80, 0); // disable pulse killer
599 tda1004x_write_byte(i2c, tda_state, TDA10046H_CONFPLL2, 10); // PLL M = 10
600 tda1004x_write_byte(i2c, tda_state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0
601 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_OFFSET, 99); // FREQOFFS = 99
602 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_PHY2_MSB, 0xd4); // } PHY2 = -11221
603 tda1004x_write_byte(i2c, tda_state, TDA10046H_FREQ_PHY2_LSB, 0x2c); // }
604 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_CONF, 0); // AGC setup
605 tda1004x_write_mask(i2c, tda_state, TDA10046H_CONF_POLARITY, 0x60, 0x60); // set AGC polarities
606 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_TUN_MIN, 0); // }
607 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_TUN_MAX, 0xff); // } AGC min/max values
608 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_IF_MIN, 0); // }
609 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_IF_MAX, 0xff); // }
610 tda1004x_write_mask(i2c, tda_state, TDA10046H_CVBER_CTRL, 0x30, 0x10); // 10^6 VBER measurement bits
611 tda1004x_write_byte(i2c, tda_state, TDA10046H_AGC_GAINS, 1); // IF gain 2, TUN gain 1
612 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 0x80, 0); // crystal is 50ppm
613 tda1004x_write_byte(i2c, tda_state, TDA1004X_CONF_TS1, 7); // MPEG2 interface config
614 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONF_TS2, 0x31, 0); // MPEG2 interface config
615 tda1004x_write_mask(i2c, tda_state, TDA10046H_CONF_TRISTATE1, 0x9e, 0); // disable AGC_TUN
616 tda1004x_write_byte(i2c, tda_state, TDA10046H_CONF_TRISTATE2, 0xe1); // tristate setup
617 tda1004x_write_byte(i2c, tda_state, TDA10046H_GPIO_OUT_SEL, 0xcc); // GPIO output config
618 tda1004x_write_mask(i2c, tda_state, TDA10046H_GPIO_SELECT, 8, 8); // GPIO select
619 tda10046h_set_bandwidth(i2c, tda_state, BANDWIDTH_8_MHZ); // default bandwidth 8 MHz
627 static int tda1004x_encode_fec(int fec)
629 // convert known FEC values
647 static int tda1004x_decode_fec(int tdafec)
649 // convert known FEC values
667 static int tda1004x_set_frequency(struct dvb_i2c_bus *i2c,
668 struct tda1004x_state *tda_state,
669 struct dvb_frontend_parameters *fe_params)
672 struct i2c_msg tuner_msg = {.addr=0, .flags=0, .buf=tuner_buf, .len=sizeof(tuner_buf) };
673 int tuner_frequency = 0;
675 int counter, counter2;
677 dprintk("%s\n", __FUNCTION__);
679 // setup the frequency buffer
680 switch (tda_state->tuner_type) {
681 case TUNER_TYPE_TD1344:
683 // setup tuner buffer
684 // ((Fif+((1000000/6)/2)) + Finput)/(1000000/6)
686 (((fe_params->frequency / 1000) * 6) + 217502) / 1000;
687 tuner_buf[0] = tuner_frequency >> 8;
688 tuner_buf[1] = tuner_frequency & 0xff;
690 if (fe_params->frequency < 550000000) {
697 tda1004x_enable_tuner_i2c(i2c, tda_state);
698 tuner_msg.addr = tda_state->tuner_address;
700 i2c->xfer(i2c, &tuner_msg, 1);
702 // wait for it to finish
704 tuner_msg.flags = I2C_M_RD;
707 while (counter++ < 100) {
708 if (i2c->xfer(i2c, &tuner_msg, 1) == 1) {
709 if (tuner_buf[0] & 0x40) {
720 tda1004x_disable_tuner_i2c(i2c, tda_state);
723 case TUNER_TYPE_TD1316:
724 // determine charge pump
725 tuner_frequency = fe_params->frequency + 36130000;
726 if (tuner_frequency < 87000000) {
728 } else if (tuner_frequency < 130000000) {
730 } else if (tuner_frequency < 160000000) {
732 } else if (tuner_frequency < 200000000) {
734 } else if (tuner_frequency < 290000000) {
736 } else if (tuner_frequency < 420000000) {
738 } else if (tuner_frequency < 480000000) {
740 } else if (tuner_frequency < 620000000) {
742 } else if (tuner_frequency < 830000000) {
744 } else if (tuner_frequency < 895000000) {
751 if (fe_params->frequency < 49000000) {
753 } else if (fe_params->frequency < 159000000) {
755 } else if (fe_params->frequency < 444000000) {
757 } else if (fe_params->frequency < 861000000) {
764 switch (fe_params->u.ofdm.bandwidth) {
765 case BANDWIDTH_6_MHZ:
769 case BANDWIDTH_7_MHZ:
773 case BANDWIDTH_8_MHZ:
782 // ((36130000+((1000000/6)/2)) + Finput)/(1000000/6)
784 (((fe_params->frequency / 1000) * 6) + 217280) / 1000;
786 // setup tuner buffer
787 tuner_buf[0] = tuner_frequency >> 8;
788 tuner_buf[1] = tuner_frequency & 0xff;
790 tuner_buf[3] = (cp << 5) | (filter << 3) | band;
793 if (tda_state->fe_type == FE_TYPE_TDA10046H) {
795 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 0x10, 0x10);
796 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x80, 0);
797 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF2, 0xC0, 0);
799 // disable agc_conf[2]
800 tda1004x_write_mask(i2c, tda_state, TDA10046H_AGC_CONF, 4, 0);
802 tda1004x_enable_tuner_i2c(i2c, tda_state);
803 tuner_msg.addr = tda_state->tuner_address;
805 if (i2c->xfer(i2c, &tuner_msg, 1) != 1) {
809 tda1004x_disable_tuner_i2c(i2c, tda_state);
810 if (tda_state->fe_type == FE_TYPE_TDA10046H)
811 tda1004x_write_mask(i2c, tda_state, TDA10046H_AGC_CONF, 4, 4);
818 dprintk("%s: success\n", __FUNCTION__);
824 static int tda1004x_set_fe(struct dvb_i2c_bus *i2c,
825 struct tda1004x_state *tda_state,
826 struct dvb_frontend_parameters *fe_params)
831 dprintk("%s\n", __FUNCTION__);
834 if ((tmp = tda1004x_set_frequency(i2c, tda_state, fe_params)) < 0)
837 // hardcoded to use auto as much as possible
838 fe_params->u.ofdm.code_rate_HP = FEC_AUTO;
839 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
840 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
842 // Set standard params.. or put them to auto
843 if ((fe_params->u.ofdm.code_rate_HP == FEC_AUTO) ||
844 (fe_params->u.ofdm.code_rate_LP == FEC_AUTO) ||
845 (fe_params->u.ofdm.constellation == QAM_AUTO) ||
846 (fe_params->u.ofdm.hierarchy_information == HIERARCHY_AUTO)) {
847 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 1, 1); // enable auto
848 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x03, 0); // turn off constellation bits
849 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x60, 0); // turn off hierarchy bits
850 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF2, 0x3f, 0); // turn off FEC bits
852 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 1, 0); // disable auto
855 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_HP);
856 if (tmp < 0) return tmp;
857 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF2, 7, tmp);
860 if (fe_params->u.ofdm.code_rate_LP != FEC_NONE) {
861 tmp = tda1004x_encode_fec(fe_params->u.ofdm.code_rate_LP);
862 if (tmp < 0) return tmp;
863 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF2, 0x38, tmp << 3);
867 switch (fe_params->u.ofdm.constellation) {
869 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 3, 0);
873 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 3, 1);
877 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 3, 2);
885 switch (fe_params->u.ofdm.hierarchy_information) {
887 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x60, 0 << 5);
891 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x60, 1 << 5);
895 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x60, 2 << 5);
899 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x60, 3 << 5);
908 switch(tda_state->fe_type) {
909 case FE_TYPE_TDA10045H:
910 tda10045h_set_bandwidth(i2c, tda_state, fe_params->u.ofdm.bandwidth);
913 case FE_TYPE_TDA10046H:
914 tda10046h_set_bandwidth(i2c, tda_state, fe_params->u.ofdm.bandwidth);
918 // need to invert the inversion for TT TDA10046H
919 inversion = fe_params->inversion;
920 if (tda_state->fe_type == FE_TYPE_TDA10046H) {
921 inversion = inversion ? INVERSION_OFF : INVERSION_ON;
927 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x20, 0);
931 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC1, 0x20, 0x20);
938 // set guard interval
939 switch (fe_params->u.ofdm.guard_interval) {
940 case GUARD_INTERVAL_1_32:
941 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 2, 0);
942 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
945 case GUARD_INTERVAL_1_16:
946 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 2, 0);
947 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x0c, 1 << 2);
950 case GUARD_INTERVAL_1_8:
951 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 2, 0);
952 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x0c, 2 << 2);
955 case GUARD_INTERVAL_1_4:
956 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 2, 0);
957 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x0c, 3 << 2);
960 case GUARD_INTERVAL_AUTO:
961 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 2, 2);
962 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x0c, 0 << 2);
969 // set transmission mode
970 switch (fe_params->u.ofdm.transmission_mode) {
971 case TRANSMISSION_MODE_2K:
972 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 4, 0);
973 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x10, 0 << 4);
976 case TRANSMISSION_MODE_8K:
977 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 4, 0);
978 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x10, 1 << 4);
981 case TRANSMISSION_MODE_AUTO:
982 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 4, 4);
983 tda1004x_write_mask(i2c, tda_state, TDA1004X_IN_CONF1, 0x10, 0);
991 switch(tda_state->fe_type) {
992 case FE_TYPE_TDA10045H:
993 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 8, 8);
994 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 8, 0);
998 case FE_TYPE_TDA10046H:
999 tda1004x_write_mask(i2c, tda_state, TDA1004X_AUTO, 0x40, 0x40);
1009 static int tda1004x_get_fe(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, struct dvb_frontend_parameters *fe_params)
1012 dprintk("%s\n", __FUNCTION__);
1015 fe_params->inversion = INVERSION_OFF;
1016 if (tda1004x_read_byte(i2c, tda_state, TDA1004X_CONFC1) & 0x20) {
1017 fe_params->inversion = INVERSION_ON;
1020 // need to invert the inversion for TT TDA10046H
1021 if (tda_state->fe_type == FE_TYPE_TDA10046H) {
1022 fe_params->inversion = fe_params->inversion ? INVERSION_OFF : INVERSION_ON;
1026 switch(tda_state->fe_type) {
1027 case FE_TYPE_TDA10045H:
1028 switch (tda1004x_read_byte(i2c, tda_state, TDA10045H_WREF_LSB)) {
1030 fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1033 fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1036 fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1041 case FE_TYPE_TDA10046H:
1042 switch (tda1004x_read_byte(i2c, tda_state, TDA10046H_TIME_WREF1)) {
1044 fe_params->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1047 fe_params->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1050 fe_params->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1057 fe_params->u.ofdm.code_rate_HP =
1058 tda1004x_decode_fec(tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF2) & 7);
1059 fe_params->u.ofdm.code_rate_LP =
1060 tda1004x_decode_fec((tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF2) >> 3) & 7);
1063 switch (tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF1) & 3) {
1065 fe_params->u.ofdm.constellation = QPSK;
1068 fe_params->u.ofdm.constellation = QAM_16;
1071 fe_params->u.ofdm.constellation = QAM_64;
1075 // transmission mode
1076 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
1077 if (tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF1) & 0x10) {
1078 fe_params->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
1082 switch ((tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF1) & 0x0c) >> 2) {
1084 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
1087 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
1090 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
1093 fe_params->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
1098 switch ((tda1004x_read_byte(i2c, tda_state, TDA1004X_OUT_CONF1) & 0x60) >> 5) {
1100 fe_params->u.ofdm.hierarchy_information = HIERARCHY_NONE;
1103 fe_params->u.ofdm.hierarchy_information = HIERARCHY_1;
1106 fe_params->u.ofdm.hierarchy_information = HIERARCHY_2;
1109 fe_params->u.ofdm.hierarchy_information = HIERARCHY_4;
1118 static int tda1004x_read_status(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, fe_status_t * fe_status)
1124 dprintk("%s\n", __FUNCTION__);
1127 status = tda1004x_read_byte(i2c, tda_state, TDA1004X_STATUS_CD);
1134 if (status & 4) *fe_status |= FE_HAS_SIGNAL;
1135 if (status & 2) *fe_status |= FE_HAS_CARRIER;
1136 if (status & 8) *fe_status |= FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
1138 // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi
1139 // is getting anything valid
1140 if (!(*fe_status & FE_HAS_VITERBI)) {
1142 cber = tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_LSB);
1143 if (cber == -1) return -EIO;
1144 status = tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_MSB);
1145 if (status == -1) return -EIO;
1146 cber |= (status << 8);
1147 tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_RESET);
1149 if (cber != 65535) {
1150 *fe_status |= FE_HAS_VITERBI;
1154 // if we DO have some valid VITERBI output, but don't already have SYNC
1155 // bytes (i.e. not LOCKED), see if the RS decoder is getting anything valid.
1156 if ((*fe_status & FE_HAS_VITERBI) && (!(*fe_status & FE_HAS_SYNC))) {
1158 vber = tda1004x_read_byte(i2c, tda_state, TDA1004X_VBER_LSB);
1159 if (vber == -1) return -EIO;
1160 status = tda1004x_read_byte(i2c, tda_state, TDA1004X_VBER_MID);
1161 if (status == -1) return -EIO;
1162 vber |= (status << 8);
1163 status = tda1004x_read_byte(i2c, tda_state, TDA1004X_VBER_MSB);
1164 if (status == -1) return -EIO;
1165 vber |= ((status << 16) & 0x0f);
1166 tda1004x_read_byte(i2c, tda_state, TDA1004X_CVBER_LUT);
1168 // if RS has passed some valid TS packets, then we must be
1169 // getting some SYNC bytes
1171 *fe_status |= FE_HAS_SYNC;
1176 dprintk("%s: fe_status=0x%x\n", __FUNCTION__, *fe_status);
1180 static int tda1004x_read_signal_strength(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, u16 * signal)
1185 dprintk("%s\n", __FUNCTION__);
1187 // determine the register to use
1188 switch(tda_state->fe_type) {
1189 case FE_TYPE_TDA10045H:
1190 reg = TDA10045H_S_AGC;
1193 case FE_TYPE_TDA10046H:
1194 reg = TDA10046H_AGC_IF_LEVEL;
1199 tmp = tda1004x_read_byte(i2c, tda_state, reg);
1204 *signal = (tmp << 8) | tmp;
1205 dprintk("%s: signal=0x%x\n", __FUNCTION__, *signal);
1210 static int tda1004x_read_snr(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, u16 * snr)
1214 dprintk("%s\n", __FUNCTION__);
1217 tmp = tda1004x_read_byte(i2c, tda_state, TDA1004X_SNR);
1225 *snr = ((tmp << 8) | tmp);
1226 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr);
1230 static int tda1004x_read_ucblocks(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, u32* ucblocks)
1236 dprintk("%s\n", __FUNCTION__);
1238 // read the UCBLOCKS and reset
1240 tmp = tda1004x_read_byte(i2c, tda_state, TDA1004X_UNCOR);
1244 while (counter++ < 5) {
1245 tda1004x_write_mask(i2c, tda_state, TDA1004X_UNCOR, 0x80, 0);
1246 tda1004x_write_mask(i2c, tda_state, TDA1004X_UNCOR, 0x80, 0);
1247 tda1004x_write_mask(i2c, tda_state, TDA1004X_UNCOR, 0x80, 0);
1249 tmp2 = tda1004x_read_byte(i2c, tda_state, TDA1004X_UNCOR);
1253 if ((tmp2 < tmp) || (tmp2 == 0))
1261 *ucblocks = 0xffffffff;
1263 dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks);
1267 static int tda1004x_read_ber(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state, u32* ber)
1271 dprintk("%s\n", __FUNCTION__);
1274 tmp = tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_LSB);
1275 if (tmp < 0) return -EIO;
1277 tmp = tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_MSB);
1278 if (tmp < 0) return -EIO;
1280 tda1004x_read_byte(i2c, tda_state, TDA1004X_CBER_RESET);
1283 dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber);
1287 static int tda1004x_sleep(struct dvb_i2c_bus *i2c, struct tda1004x_state* tda_state)
1289 switch(tda_state->fe_type) {
1290 case FE_TYPE_TDA10045H:
1291 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFADC1, 0x10, 0x10);
1294 case FE_TYPE_TDA10046H:
1295 tda1004x_write_mask(i2c, tda_state, TDA1004X_CONFC4, 1, 1);
1303 static int tda1004x_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg)
1306 struct dvb_i2c_bus *i2c = fe->i2c;
1307 struct tda1004x_state *tda_state = (struct tda1004x_state *) fe->data;
1309 dprintk("%s: cmd=0x%x\n", __FUNCTION__, cmd);
1313 switch(tda_state->fe_type) {
1314 case FE_TYPE_TDA10045H:
1315 memcpy(arg, &tda10045h_info, sizeof(struct dvb_frontend_info));
1318 case FE_TYPE_TDA10046H:
1319 memcpy(arg, &tda10046h_info, sizeof(struct dvb_frontend_info));
1324 case FE_READ_STATUS:
1325 return tda1004x_read_status(i2c, tda_state, (fe_status_t *) arg);
1328 return tda1004x_read_ber(i2c, tda_state, (u32 *) arg);
1330 case FE_READ_SIGNAL_STRENGTH:
1331 return tda1004x_read_signal_strength(i2c, tda_state, (u16 *) arg);
1334 return tda1004x_read_snr(i2c, tda_state, (u16 *) arg);
1336 case FE_READ_UNCORRECTED_BLOCKS:
1337 return tda1004x_read_ucblocks(i2c, tda_state, (u32 *) arg);
1339 case FE_SET_FRONTEND:
1340 return tda1004x_set_fe(i2c, tda_state, (struct dvb_frontend_parameters*) arg);
1342 case FE_GET_FRONTEND:
1343 return tda1004x_get_fe(i2c, tda_state, (struct dvb_frontend_parameters*) arg);
1346 tda_state->initialised = 0;
1347 return tda1004x_sleep(i2c, tda_state);
1351 // don't bother reinitialising
1352 if (tda_state->initialised)
1355 // OK, perform initialisation
1356 switch(tda_state->fe_type) {
1357 case FE_TYPE_TDA10045H:
1358 status = tda10045h_init(i2c, tda_state);
1361 case FE_TYPE_TDA10046H:
1362 status = tda10046h_init(i2c, tda_state);
1366 tda_state->initialised = 1;
1369 case FE_GET_TUNE_SETTINGS:
1371 struct dvb_frontend_tune_settings* fesettings = (struct dvb_frontend_tune_settings*) arg;
1372 fesettings->min_delay_ms = 800;
1373 fesettings->step_size = 166667;
1374 fesettings->max_drift = 166667*2;
1386 static int tda1004x_attach(struct dvb_i2c_bus *i2c, void **data)
1388 int tda1004x_address = -1;
1389 int tuner_address = -1;
1391 int tuner_type = -1;
1392 struct tda1004x_state tda_state;
1393 struct tda1004x_state* ptda_state;
1394 struct i2c_msg tuner_msg = {.addr=0, .flags=0, .buf=NULL, .len=0 };
1395 static u8 td1344_init[] = { 0x0b, 0xf5, 0x88, 0xab };
1396 static u8 td1316_init[] = { 0x0b, 0xf5, 0x85, 0xab };
1397 static u8 td1316_init_tda10046h[] = { 0x0b, 0xf5, 0x80, 0xab };
1400 dprintk("%s\n", __FUNCTION__);
1402 // probe for tda10045h
1403 if (tda1004x_address == -1) {
1404 tda_state.tda1004x_address = 0x08;
1405 if (tda1004x_read_byte(i2c, &tda_state, TDA1004X_CHIPID) == 0x25) {
1406 tda1004x_address = 0x08;
1407 fe_type = FE_TYPE_TDA10045H;
1408 printk("tda1004x: Detected Philips TDA10045H.\n");
1412 // probe for tda10046h
1413 if (tda1004x_address == -1) {
1414 tda_state.tda1004x_address = 0x08;
1415 if (tda1004x_read_byte(i2c, &tda_state, TDA1004X_CHIPID) == 0x46) {
1416 tda1004x_address = 0x08;
1417 fe_type = FE_TYPE_TDA10046H;
1418 printk("tda1004x: Detected Philips TDA10046H.\n");
1422 // did we find a frontend?
1423 if (tda1004x_address == -1) {
1427 // enable access to the tuner
1428 tda1004x_enable_tuner_i2c(i2c, &tda_state);
1430 // check for a TD1344 first
1431 if (tuner_address == -1) {
1432 tuner_msg.addr = 0x61;
1433 tuner_msg.buf = td1344_init;
1434 tuner_msg.len = sizeof(td1344_init);
1435 if (i2c->xfer(i2c, &tuner_msg, 1) == 1) {
1437 tuner_address = 0x61;
1438 tuner_type = TUNER_TYPE_TD1344;
1439 printk("tda1004x: Detected Philips TD1344 tuner.\n");
1443 // OK, try a TD1316 on address 0x63
1444 if (tuner_address == -1) {
1445 tuner_msg.addr = 0x63;
1446 tuner_msg.buf = td1316_init;
1447 tuner_msg.len = sizeof(td1316_init);
1448 if (i2c->xfer(i2c, &tuner_msg, 1) == 1) {
1450 tuner_address = 0x63;
1451 tuner_type = TUNER_TYPE_TD1316;
1452 printk("tda1004x: Detected Philips TD1316 tuner.\n");
1456 // OK, TD1316 again, on address 0x60 (TDA10046H)
1457 if (tuner_address == -1) {
1458 tuner_msg.addr = 0x60;
1459 tuner_msg.buf = td1316_init_tda10046h;
1460 tuner_msg.len = sizeof(td1316_init_tda10046h);
1461 if (i2c->xfer(i2c, &tuner_msg, 1) == 1) {
1463 tuner_address = 0x60;
1464 tuner_type = TUNER_TYPE_TD1316;
1465 printk("tda1004x: Detected Philips TD1316 tuner.\n");
1468 tda1004x_disable_tuner_i2c(i2c, &tda_state);
1470 // did we find a tuner?
1471 if (tuner_address == -1) {
1472 printk("tda1004x: Detected, but with unknown tuner.\n");
1477 tda_state.tda1004x_address = tda1004x_address;
1478 tda_state.fe_type = fe_type;
1479 tda_state.tuner_address = tuner_address;
1480 tda_state.tuner_type = tuner_type;
1481 tda_state.initialised = 0;
1484 if ((status = tda1004x_fwupload(i2c, &tda_state)) != 0) return status;
1486 // create the real state we'll be passing about
1487 if ((ptda_state = (struct tda1004x_state*) kmalloc(sizeof(struct tda1004x_state), GFP_KERNEL)) == NULL) {
1490 memcpy(ptda_state, &tda_state, sizeof(struct tda1004x_state));
1494 switch(tda_state.fe_type) {
1495 case FE_TYPE_TDA10045H:
1496 return dvb_register_frontend(tda1004x_ioctl, i2c, ptda_state, &tda10045h_info);
1498 case FE_TYPE_TDA10046H:
1499 return dvb_register_frontend(tda1004x_ioctl, i2c, ptda_state, &tda10046h_info);
1502 // should not get here
1508 void tda1004x_detach(struct dvb_i2c_bus *i2c, void *data)
1510 dprintk("%s\n", __FUNCTION__);
1513 dvb_unregister_frontend(tda1004x_ioctl, i2c);
1518 int __init init_tda1004x(void)
1520 return dvb_register_i2c_device(THIS_MODULE, tda1004x_attach, tda1004x_detach);
1525 void __exit exit_tda1004x(void)
1527 dvb_unregister_i2c_device(tda1004x_attach);
1530 module_init(init_tda1004x);
1531 module_exit(exit_tda1004x);
1533 MODULE_DESCRIPTION("Philips TDA10045H & TDA10046H DVB-T Frontend");
1534 MODULE_AUTHOR("Andrew de Quincey & Robert Schlabbach");
1535 MODULE_LICENSE("GPL");
1537 MODULE_PARM(tda1004x_debug, "i");
1538 MODULE_PARM_DESC(tda1004x_debug, "enable verbose debug messages");
1540 MODULE_PARM(tda1004x_firmware, "s");
1541 MODULE_PARM_DESC(tda1004x_firmware, "Where to find the firmware file");