2 Driver for Philips tda1004xh OFDM Demodulator
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.
23 * This driver needs external firmware. Please use the commands
24 * "<kerneldir>/Documentation/dvb/get_dvb_firmware tda10045",
25 * "<kerneldir>/Documentation/dvb/get_dvb_firmware tda10046" to
26 * download/extract them, and then copy them to /usr/lib/hotplug/firmware
27 * or /lib/firmware (depending on configuration of firmware hotplug).
29 #define TDA10045_DEFAULT_FIRMWARE "dvb-fe-tda10045.fw"
30 #define TDA10046_DEFAULT_FIRMWARE "dvb-fe-tda10046.fw"
32 #include <linux/init.h>
33 #include <linux/module.h>
34 #include <linux/moduleparam.h>
35 #include <linux/device.h>
36 #include <linux/jiffies.h>
37 #include <linux/string.h>
38 #include <linux/slab.h>
40 #include "dvb_frontend.h"
44 TDA1004X_DEMOD_TDA10045
,
45 TDA1004X_DEMOD_TDA10046
,
48 struct tda1004x_state
{
49 struct i2c_adapter
* i2c
;
50 struct dvb_frontend_ops ops
;
51 const struct tda1004x_config
* config
;
52 struct dvb_frontend frontend
;
54 /* private demod data */
55 enum tda1004x_demod demod_type
;
59 #define dprintk(args...) \
61 if (debug) printk(KERN_DEBUG "tda1004x: " args); \
64 #define TDA1004X_CHIPID 0x00
65 #define TDA1004X_AUTO 0x01
66 #define TDA1004X_IN_CONF1 0x02
67 #define TDA1004X_IN_CONF2 0x03
68 #define TDA1004X_OUT_CONF1 0x04
69 #define TDA1004X_OUT_CONF2 0x05
70 #define TDA1004X_STATUS_CD 0x06
71 #define TDA1004X_CONFC4 0x07
72 #define TDA1004X_DSSPARE2 0x0C
73 #define TDA10045H_CODE_IN 0x0D
74 #define TDA10045H_FWPAGE 0x0E
75 #define TDA1004X_SCAN_CPT 0x10
76 #define TDA1004X_DSP_CMD 0x11
77 #define TDA1004X_DSP_ARG 0x12
78 #define TDA1004X_DSP_DATA1 0x13
79 #define TDA1004X_DSP_DATA2 0x14
80 #define TDA1004X_CONFADC1 0x15
81 #define TDA1004X_CONFC1 0x16
82 #define TDA10045H_S_AGC 0x1a
83 #define TDA10046H_AGC_TUN_LEVEL 0x1a
84 #define TDA1004X_SNR 0x1c
85 #define TDA1004X_CONF_TS1 0x1e
86 #define TDA1004X_CONF_TS2 0x1f
87 #define TDA1004X_CBER_RESET 0x20
88 #define TDA1004X_CBER_MSB 0x21
89 #define TDA1004X_CBER_LSB 0x22
90 #define TDA1004X_CVBER_LUT 0x23
91 #define TDA1004X_VBER_MSB 0x24
92 #define TDA1004X_VBER_MID 0x25
93 #define TDA1004X_VBER_LSB 0x26
94 #define TDA1004X_UNCOR 0x27
96 #define TDA10045H_CONFPLL_P 0x2D
97 #define TDA10045H_CONFPLL_M_MSB 0x2E
98 #define TDA10045H_CONFPLL_M_LSB 0x2F
99 #define TDA10045H_CONFPLL_N 0x30
101 #define TDA10046H_CONFPLL1 0x2D
102 #define TDA10046H_CONFPLL2 0x2F
103 #define TDA10046H_CONFPLL3 0x30
104 #define TDA10046H_TIME_WREF1 0x31
105 #define TDA10046H_TIME_WREF2 0x32
106 #define TDA10046H_TIME_WREF3 0x33
107 #define TDA10046H_TIME_WREF4 0x34
108 #define TDA10046H_TIME_WREF5 0x35
110 #define TDA10045H_UNSURW_MSB 0x31
111 #define TDA10045H_UNSURW_LSB 0x32
112 #define TDA10045H_WREF_MSB 0x33
113 #define TDA10045H_WREF_MID 0x34
114 #define TDA10045H_WREF_LSB 0x35
115 #define TDA10045H_MUXOUT 0x36
116 #define TDA1004X_CONFADC2 0x37
118 #define TDA10045H_IOFFSET 0x38
120 #define TDA10046H_CONF_TRISTATE1 0x3B
121 #define TDA10046H_CONF_TRISTATE2 0x3C
122 #define TDA10046H_CONF_POLARITY 0x3D
123 #define TDA10046H_FREQ_OFFSET 0x3E
124 #define TDA10046H_GPIO_OUT_SEL 0x41
125 #define TDA10046H_GPIO_SELECT 0x42
126 #define TDA10046H_AGC_CONF 0x43
127 #define TDA10046H_AGC_THR 0x44
128 #define TDA10046H_AGC_RENORM 0x45
129 #define TDA10046H_AGC_GAINS 0x46
130 #define TDA10046H_AGC_TUN_MIN 0x47
131 #define TDA10046H_AGC_TUN_MAX 0x48
132 #define TDA10046H_AGC_IF_MIN 0x49
133 #define TDA10046H_AGC_IF_MAX 0x4A
135 #define TDA10046H_FREQ_PHY2_MSB 0x4D
136 #define TDA10046H_FREQ_PHY2_LSB 0x4E
138 #define TDA10046H_CVBER_CTRL 0x4F
139 #define TDA10046H_AGC_IF_LEVEL 0x52
140 #define TDA10046H_CODE_CPT 0x57
141 #define TDA10046H_CODE_IN 0x58
144 static int tda1004x_write_byteI(struct tda1004x_state
*state
, int reg
, int data
)
147 u8 buf
[] = { reg
, data
};
148 struct i2c_msg msg
= { .flags
= 0, .buf
= buf
, .len
= 2 };
150 dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__
, reg
, data
);
152 msg
.addr
= state
->config
->demod_address
;
153 ret
= i2c_transfer(state
->i2c
, &msg
, 1);
156 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
157 __FUNCTION__
, reg
, data
, ret
);
159 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__
,
161 return (ret
!= 1) ? -1 : 0;
164 static int tda1004x_read_byte(struct tda1004x_state
*state
, int reg
)
169 struct i2c_msg msg
[] = {{ .flags
= 0, .buf
= b0
, .len
= 1 },
170 { .flags
= I2C_M_RD
, .buf
= b1
, .len
= 1 }};
172 dprintk("%s: reg=0x%x\n", __FUNCTION__
, reg
);
174 msg
[0].addr
= state
->config
->demod_address
;
175 msg
[1].addr
= state
->config
->demod_address
;
176 ret
= i2c_transfer(state
->i2c
, msg
, 2);
179 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__
, reg
,
184 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__
,
189 static int tda1004x_write_mask(struct tda1004x_state
*state
, int reg
, int mask
, int data
)
192 dprintk("%s: reg=0x%x, mask=0x%x, data=0x%x\n", __FUNCTION__
, reg
,
195 // read a byte and check
196 val
= tda1004x_read_byte(state
, reg
);
204 // write it out again
205 return tda1004x_write_byteI(state
, reg
, val
);
208 static int tda1004x_write_buf(struct tda1004x_state
*state
, int reg
, unsigned char *buf
, int len
)
213 dprintk("%s: reg=0x%x, len=0x%x\n", __FUNCTION__
, reg
, len
);
216 for (i
= 0; i
< len
; i
++) {
217 result
= tda1004x_write_byteI(state
, reg
+ i
, buf
[i
]);
225 static int tda1004x_enable_tuner_i2c(struct tda1004x_state
*state
)
228 dprintk("%s\n", __FUNCTION__
);
230 result
= tda1004x_write_mask(state
, TDA1004X_CONFC4
, 2, 2);
235 static int tda1004x_disable_tuner_i2c(struct tda1004x_state
*state
)
237 dprintk("%s\n", __FUNCTION__
);
239 return tda1004x_write_mask(state
, TDA1004X_CONFC4
, 2, 0);
242 static int tda10045h_set_bandwidth(struct tda1004x_state
*state
,
243 fe_bandwidth_t bandwidth
)
245 static u8 bandwidth_6mhz
[] = { 0x02, 0x00, 0x3d, 0x00, 0x60, 0x1e, 0xa7, 0x45, 0x4f };
246 static u8 bandwidth_7mhz
[] = { 0x02, 0x00, 0x37, 0x00, 0x4a, 0x2f, 0x6d, 0x76, 0xdb };
247 static u8 bandwidth_8mhz
[] = { 0x02, 0x00, 0x3d, 0x00, 0x48, 0x17, 0x89, 0xc7, 0x14 };
250 case BANDWIDTH_6_MHZ
:
251 tda1004x_write_buf(state
, TDA10045H_CONFPLL_P
, bandwidth_6mhz
, sizeof(bandwidth_6mhz
));
254 case BANDWIDTH_7_MHZ
:
255 tda1004x_write_buf(state
, TDA10045H_CONFPLL_P
, bandwidth_7mhz
, sizeof(bandwidth_7mhz
));
258 case BANDWIDTH_8_MHZ
:
259 tda1004x_write_buf(state
, TDA10045H_CONFPLL_P
, bandwidth_8mhz
, sizeof(bandwidth_8mhz
));
266 tda1004x_write_byteI(state
, TDA10045H_IOFFSET
, 0);
271 static int tda10046h_set_bandwidth(struct tda1004x_state
*state
,
272 fe_bandwidth_t bandwidth
)
274 static u8 bandwidth_6mhz_53M
[] = { 0x7b, 0x2e, 0x11, 0xf0, 0xd2 };
275 static u8 bandwidth_7mhz_53M
[] = { 0x6a, 0x02, 0x6a, 0x43, 0x9f };
276 static u8 bandwidth_8mhz_53M
[] = { 0x5c, 0x32, 0xc2, 0x96, 0x6d };
278 static u8 bandwidth_6mhz_48M
[] = { 0x70, 0x02, 0x49, 0x24, 0x92 };
279 static u8 bandwidth_7mhz_48M
[] = { 0x60, 0x02, 0xaa, 0xaa, 0xab };
280 static u8 bandwidth_8mhz_48M
[] = { 0x54, 0x03, 0x0c, 0x30, 0xc3 };
283 if ((state
->config
->if_freq
== TDA10046_FREQ_045
) ||
284 (state
->config
->if_freq
== TDA10046_FREQ_052
))
289 case BANDWIDTH_6_MHZ
:
291 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_6mhz_53M
,
292 sizeof(bandwidth_6mhz_53M
));
294 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_6mhz_48M
,
295 sizeof(bandwidth_6mhz_48M
));
296 if (state
->config
->if_freq
== TDA10046_FREQ_045
) {
297 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0x0a);
298 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0xab);
302 case BANDWIDTH_7_MHZ
:
304 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_7mhz_53M
,
305 sizeof(bandwidth_7mhz_53M
));
307 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_7mhz_48M
,
308 sizeof(bandwidth_7mhz_48M
));
309 if (state
->config
->if_freq
== TDA10046_FREQ_045
) {
310 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0x0c);
311 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0x00);
315 case BANDWIDTH_8_MHZ
:
317 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_8mhz_53M
,
318 sizeof(bandwidth_8mhz_53M
));
320 tda1004x_write_buf(state
, TDA10046H_TIME_WREF1
, bandwidth_8mhz_48M
,
321 sizeof(bandwidth_8mhz_48M
));
322 if (state
->config
->if_freq
== TDA10046_FREQ_045
) {
323 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0x0d);
324 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0x55);
335 static int tda1004x_do_upload(struct tda1004x_state
*state
,
336 unsigned char *mem
, unsigned int len
,
337 u8 dspCodeCounterReg
, u8 dspCodeInReg
)
340 struct i2c_msg fw_msg
= { .flags
= 0, .buf
= buf
, .len
= 0 };
344 /* clear code counter */
345 tda1004x_write_byteI(state
, dspCodeCounterReg
, 0);
346 fw_msg
.addr
= state
->config
->demod_address
;
348 buf
[0] = dspCodeInReg
;
350 // work out how much to send this time
356 memcpy(buf
+ 1, mem
+ pos
, tx_size
);
357 fw_msg
.len
= tx_size
+ 1;
358 if (i2c_transfer(state
->i2c
, &fw_msg
, 1) != 1) {
359 printk(KERN_ERR
"tda1004x: Error during firmware upload\n");
364 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__
, pos
);
366 // give the DSP a chance to settle 03/10/05 Hac
372 static int tda1004x_check_upload_ok(struct tda1004x_state
*state
)
375 unsigned long timeout
;
377 if (state
->demod_type
== TDA1004X_DEMOD_TDA10046
) {
378 timeout
= jiffies
+ 2 * HZ
;
379 while(!(tda1004x_read_byte(state
, TDA1004X_STATUS_CD
) & 0x20)) {
380 if (time_after(jiffies
, timeout
)) {
381 printk(KERN_ERR
"tda1004x: timeout waiting for DSP ready\n");
389 // check upload was OK
390 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 0x10, 0); // we want to read from the DSP
391 tda1004x_write_byteI(state
, TDA1004X_DSP_CMD
, 0x67);
393 data1
= tda1004x_read_byte(state
, TDA1004X_DSP_DATA1
);
394 data2
= tda1004x_read_byte(state
, TDA1004X_DSP_DATA2
);
395 if (data1
!= 0x67 || data2
< 0x20 || data2
> 0x2e) {
396 printk(KERN_INFO
"tda1004x: found firmware revision %x -- invalid\n", data2
);
399 printk(KERN_INFO
"tda1004x: found firmware revision %x -- ok\n", data2
);
403 static int tda10045_fwupload(struct dvb_frontend
* fe
)
405 struct tda1004x_state
* state
= fe
->demodulator_priv
;
407 const struct firmware
*fw
;
409 /* don't re-upload unless necessary */
410 if (tda1004x_check_upload_ok(state
) == 0)
413 /* request the firmware, this will block until someone uploads it */
414 printk(KERN_INFO
"tda1004x: waiting for firmware upload (%s)...\n", TDA10045_DEFAULT_FIRMWARE
);
415 ret
= state
->config
->request_firmware(fe
, &fw
, TDA10045_DEFAULT_FIRMWARE
);
417 printk(KERN_ERR
"tda1004x: no firmware upload (timeout or file not found?)\n");
422 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 0x10, 0);
423 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 8, 8);
424 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 8, 0);
428 tda10045h_set_bandwidth(state
, BANDWIDTH_8_MHZ
);
430 ret
= tda1004x_do_upload(state
, fw
->data
, fw
->size
, TDA10045H_FWPAGE
, TDA10045H_CODE_IN
);
431 release_firmware(fw
);
434 printk(KERN_INFO
"tda1004x: firmware upload complete\n");
436 /* wait for DSP to initialise */
437 /* DSPREADY doesn't seem to work on the TDA10045H */
440 return tda1004x_check_upload_ok(state
);
443 static void tda10046_init_plls(struct dvb_frontend
* fe
)
445 struct tda1004x_state
* state
= fe
->demodulator_priv
;
448 if ((state
->config
->if_freq
== TDA10046_FREQ_045
) ||
449 (state
->config
->if_freq
== TDA10046_FREQ_052
))
454 tda1004x_write_byteI(state
, TDA10046H_CONFPLL1
, 0xf0);
455 if(tda10046_clk53m
) {
456 printk(KERN_INFO
"tda1004x: setting up plls for 53MHz sampling clock\n");
457 tda1004x_write_byteI(state
, TDA10046H_CONFPLL2
, 0x08); // PLL M = 8
459 printk(KERN_INFO
"tda1004x: setting up plls for 48MHz sampling clock\n");
460 tda1004x_write_byteI(state
, TDA10046H_CONFPLL2
, 0x03); // PLL M = 3
462 if (state
->config
->xtal_freq
== TDA10046_XTAL_4M
) {
463 dprintk("%s: setting up PLLs for a 4 MHz Xtal\n", __FUNCTION__
);
464 tda1004x_write_byteI(state
, TDA10046H_CONFPLL3
, 0); // PLL P = N = 0
466 dprintk("%s: setting up PLLs for a 16 MHz Xtal\n", __FUNCTION__
);
467 tda1004x_write_byteI(state
, TDA10046H_CONFPLL3
, 3); // PLL P = 0, N = 3
470 tda1004x_write_byteI(state
, TDA10046H_FREQ_OFFSET
, 0x67);
472 tda1004x_write_byteI(state
, TDA10046H_FREQ_OFFSET
, 0x72);
473 /* Note clock frequency is handled implicitly */
474 switch (state
->config
->if_freq
) {
475 case TDA10046_FREQ_045
:
476 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0x0c);
477 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0x00);
479 case TDA10046_FREQ_052
:
480 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0x0d);
481 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0xc7);
483 case TDA10046_FREQ_3617
:
484 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0xd7);
485 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0x59);
487 case TDA10046_FREQ_3613
:
488 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_MSB
, 0xd7);
489 tda1004x_write_byteI(state
, TDA10046H_FREQ_PHY2_LSB
, 0x3f);
492 tda10046h_set_bandwidth(state
, BANDWIDTH_8_MHZ
); // default bandwidth 8 MHz
493 /* let the PLLs settle */
497 static int tda10046_fwupload(struct dvb_frontend
* fe
)
499 struct tda1004x_state
* state
= fe
->demodulator_priv
;
501 const struct firmware
*fw
;
503 /* reset + wake up chip */
504 if (state
->config
->xtal_freq
== TDA10046_XTAL_4M
) {
505 tda1004x_write_byteI(state
, TDA1004X_CONFC4
, 0);
507 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __FUNCTION__
);
508 tda1004x_write_byteI(state
, TDA1004X_CONFC4
, 0x80);
510 tda1004x_write_mask(state
, TDA10046H_CONF_TRISTATE1
, 1, 0);
511 /* let the clocks recover from sleep */
514 /* The PLLs need to be reprogrammed after sleep */
515 tda10046_init_plls(fe
);
517 /* don't re-upload unless necessary */
518 if (tda1004x_check_upload_ok(state
) == 0)
521 if (state
->config
->request_firmware
!= NULL
) {
522 /* request the firmware, this will block until someone uploads it */
523 printk(KERN_INFO
"tda1004x: waiting for firmware upload...\n");
524 ret
= state
->config
->request_firmware(fe
, &fw
, TDA10046_DEFAULT_FIRMWARE
);
526 printk(KERN_ERR
"tda1004x: no firmware upload (timeout or file not found?)\n");
529 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 8, 8); // going to boot from HOST
530 ret
= tda1004x_do_upload(state
, fw
->data
, fw
->size
, TDA10046H_CODE_CPT
, TDA10046H_CODE_IN
);
531 release_firmware(fw
);
535 /* boot from firmware eeprom */
536 printk(KERN_INFO
"tda1004x: booting from eeprom\n");
537 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 4, 4);
540 return tda1004x_check_upload_ok(state
);
543 static int tda1004x_encode_fec(int fec
)
545 // convert known FEC values
563 static int tda1004x_decode_fec(int tdafec
)
565 // convert known FEC values
583 int tda1004x_write_byte(struct dvb_frontend
* fe
, int reg
, int data
)
585 struct tda1004x_state
* state
= fe
->demodulator_priv
;
587 return tda1004x_write_byteI(state
, reg
, data
);
590 static int tda10045_init(struct dvb_frontend
* fe
)
592 struct tda1004x_state
* state
= fe
->demodulator_priv
;
594 dprintk("%s\n", __FUNCTION__
);
596 if (tda10045_fwupload(fe
)) {
597 printk("tda1004x: firmware upload failed\n");
601 tda1004x_write_mask(state
, TDA1004X_CONFADC1
, 0x10, 0); // wake up the ADC
604 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 0x20, 0); // disable DSP watchdog timer
605 tda1004x_write_mask(state
, TDA1004X_AUTO
, 8, 0); // select HP stream
606 tda1004x_write_mask(state
, TDA1004X_CONFC1
, 0x40, 0); // set polarity of VAGC signal
607 tda1004x_write_mask(state
, TDA1004X_CONFC1
, 0x80, 0x80); // enable pulse killer
608 tda1004x_write_mask(state
, TDA1004X_AUTO
, 0x10, 0x10); // enable auto offset
609 tda1004x_write_mask(state
, TDA1004X_IN_CONF2
, 0xC0, 0x0); // no frequency offset
610 tda1004x_write_byteI(state
, TDA1004X_CONF_TS1
, 0); // setup MPEG2 TS interface
611 tda1004x_write_byteI(state
, TDA1004X_CONF_TS2
, 0); // setup MPEG2 TS interface
612 tda1004x_write_mask(state
, TDA1004X_VBER_MSB
, 0xe0, 0xa0); // 10^6 VBER measurement bits
613 tda1004x_write_mask(state
, TDA1004X_CONFC1
, 0x10, 0); // VAGC polarity
614 tda1004x_write_byteI(state
, TDA1004X_CONFADC1
, 0x2e);
616 tda1004x_write_mask(state
, 0x1f, 0x01, state
->config
->invert_oclk
);
621 static int tda10046_init(struct dvb_frontend
* fe
)
623 struct tda1004x_state
* state
= fe
->demodulator_priv
;
624 dprintk("%s\n", __FUNCTION__
);
626 if (tda10046_fwupload(fe
)) {
627 printk("tda1004x: firmware upload failed\n");
632 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 0x20, 0); // disable DSP watchdog timer
633 tda1004x_write_byteI(state
, TDA1004X_AUTO
, 0x87); // 100 ppm crystal, select HP stream
634 tda1004x_write_byteI(state
, TDA1004X_CONFC1
, 0x88); // enable pulse killer
636 switch (state
->config
->agc_config
) {
637 case TDA10046_AGC_DEFAULT
:
638 tda1004x_write_byteI(state
, TDA10046H_AGC_CONF
, 0x00); // AGC setup
639 tda1004x_write_byteI(state
, TDA10046H_CONF_POLARITY
, 0x60); // set AGC polarities
641 case TDA10046_AGC_IFO_AUTO_NEG
:
642 tda1004x_write_byteI(state
, TDA10046H_AGC_CONF
, 0x0a); // AGC setup
643 tda1004x_write_byteI(state
, TDA10046H_CONF_POLARITY
, 0x60); // set AGC polarities
645 case TDA10046_AGC_IFO_AUTO_POS
:
646 tda1004x_write_byteI(state
, TDA10046H_AGC_CONF
, 0x0a); // AGC setup
647 tda1004x_write_byteI(state
, TDA10046H_CONF_POLARITY
, 0x00); // set AGC polarities
649 case TDA10046_AGC_TDA827X
:
650 tda1004x_write_byteI(state
, TDA10046H_AGC_CONF
, 0x02); // AGC setup
651 tda1004x_write_byteI(state
, TDA10046H_AGC_THR
, 0x70); // AGC Threshold
652 tda1004x_write_byteI(state
, TDA10046H_AGC_RENORM
, 0x08); // Gain Renormalize
653 tda1004x_write_byteI(state
, TDA10046H_CONF_POLARITY
, 0x6a); // set AGC polarities
655 case TDA10046_AGC_TDA827X_GPL
:
656 tda1004x_write_byteI(state
, TDA10046H_AGC_CONF
, 0x02); // AGC setup
657 tda1004x_write_byteI(state
, TDA10046H_AGC_THR
, 0x70); // AGC Threshold
658 tda1004x_write_byteI(state
, TDA10046H_AGC_RENORM
, 0x08); // Gain Renormalize
659 tda1004x_write_byteI(state
, TDA10046H_CONF_POLARITY
, 0x60); // set AGC polarities
662 tda1004x_write_byteI(state
, TDA1004X_CONFADC2
, 0x38);
663 tda1004x_write_byteI(state
, TDA10046H_CONF_TRISTATE1
, 0x61); // Turn both AGC outputs on
664 tda1004x_write_byteI(state
, TDA10046H_AGC_TUN_MIN
, 0); // }
665 tda1004x_write_byteI(state
, TDA10046H_AGC_TUN_MAX
, 0xff); // } AGC min/max values
666 tda1004x_write_byteI(state
, TDA10046H_AGC_IF_MIN
, 0); // }
667 tda1004x_write_byteI(state
, TDA10046H_AGC_IF_MAX
, 0xff); // }
668 tda1004x_write_byteI(state
, TDA10046H_AGC_GAINS
, 0x12); // IF gain 2, TUN gain 1
669 tda1004x_write_byteI(state
, TDA10046H_CVBER_CTRL
, 0x1a); // 10^6 VBER measurement bits
670 tda1004x_write_byteI(state
, TDA1004X_CONF_TS1
, 7); // MPEG2 interface config
671 tda1004x_write_byteI(state
, TDA1004X_CONF_TS2
, 0xc0); // MPEG2 interface config
672 // tda1004x_write_mask(state, 0x50, 0x80, 0x80); // handle out of guard echoes
673 tda1004x_write_mask(state
, 0x3a, 0x80, state
->config
->invert_oclk
<< 7);
678 static int tda1004x_set_fe(struct dvb_frontend
* fe
,
679 struct dvb_frontend_parameters
*fe_params
)
681 struct tda1004x_state
* state
= fe
->demodulator_priv
;
685 dprintk("%s\n", __FUNCTION__
);
687 if (state
->demod_type
== TDA1004X_DEMOD_TDA10046
) {
689 tda1004x_write_mask(state
, TDA1004X_AUTO
, 0x10, 0x10);
690 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x80, 0);
691 tda1004x_write_mask(state
, TDA1004X_IN_CONF2
, 0xC0, 0);
693 // disable agc_conf[2]
694 tda1004x_write_mask(state
, TDA10046H_AGC_CONF
, 4, 0);
698 if (fe
->ops
->tuner_ops
.set_params
) {
699 fe
->ops
->tuner_ops
.set_params(fe
, fe_params
);
700 if (fe
->ops
->i2c_gate_ctrl
) fe
->ops
->i2c_gate_ctrl(fe
, 0);
703 // Hardcoded to use auto as much as possible on the TDA10045 as it
704 // is very unreliable if AUTO mode is _not_ used.
705 if (state
->demod_type
== TDA1004X_DEMOD_TDA10045
) {
706 fe_params
->u
.ofdm
.code_rate_HP
= FEC_AUTO
;
707 fe_params
->u
.ofdm
.guard_interval
= GUARD_INTERVAL_AUTO
;
708 fe_params
->u
.ofdm
.transmission_mode
= TRANSMISSION_MODE_AUTO
;
711 // Set standard params.. or put them to auto
712 if ((fe_params
->u
.ofdm
.code_rate_HP
== FEC_AUTO
) ||
713 (fe_params
->u
.ofdm
.code_rate_LP
== FEC_AUTO
) ||
714 (fe_params
->u
.ofdm
.constellation
== QAM_AUTO
) ||
715 (fe_params
->u
.ofdm
.hierarchy_information
== HIERARCHY_AUTO
)) {
716 tda1004x_write_mask(state
, TDA1004X_AUTO
, 1, 1); // enable auto
717 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x03, 0); // turn off constellation bits
718 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x60, 0); // turn off hierarchy bits
719 tda1004x_write_mask(state
, TDA1004X_IN_CONF2
, 0x3f, 0); // turn off FEC bits
721 tda1004x_write_mask(state
, TDA1004X_AUTO
, 1, 0); // disable auto
724 tmp
= tda1004x_encode_fec(fe_params
->u
.ofdm
.code_rate_HP
);
727 tda1004x_write_mask(state
, TDA1004X_IN_CONF2
, 7, tmp
);
730 tmp
= tda1004x_encode_fec(fe_params
->u
.ofdm
.code_rate_LP
);
733 tda1004x_write_mask(state
, TDA1004X_IN_CONF2
, 0x38, tmp
<< 3);
736 switch (fe_params
->u
.ofdm
.constellation
) {
738 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 3, 0);
742 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 3, 1);
746 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 3, 2);
754 switch (fe_params
->u
.ofdm
.hierarchy_information
) {
756 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x60, 0 << 5);
760 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x60, 1 << 5);
764 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x60, 2 << 5);
768 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x60, 3 << 5);
777 switch (state
->demod_type
) {
778 case TDA1004X_DEMOD_TDA10045
:
779 tda10045h_set_bandwidth(state
, fe_params
->u
.ofdm
.bandwidth
);
782 case TDA1004X_DEMOD_TDA10046
:
783 tda10046h_set_bandwidth(state
, fe_params
->u
.ofdm
.bandwidth
);
788 inversion
= fe_params
->inversion
;
789 if (state
->config
->invert
)
790 inversion
= inversion
? INVERSION_OFF
: INVERSION_ON
;
793 tda1004x_write_mask(state
, TDA1004X_CONFC1
, 0x20, 0);
797 tda1004x_write_mask(state
, TDA1004X_CONFC1
, 0x20, 0x20);
804 // set guard interval
805 switch (fe_params
->u
.ofdm
.guard_interval
) {
806 case GUARD_INTERVAL_1_32
:
807 tda1004x_write_mask(state
, TDA1004X_AUTO
, 2, 0);
808 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x0c, 0 << 2);
811 case GUARD_INTERVAL_1_16
:
812 tda1004x_write_mask(state
, TDA1004X_AUTO
, 2, 0);
813 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x0c, 1 << 2);
816 case GUARD_INTERVAL_1_8
:
817 tda1004x_write_mask(state
, TDA1004X_AUTO
, 2, 0);
818 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x0c, 2 << 2);
821 case GUARD_INTERVAL_1_4
:
822 tda1004x_write_mask(state
, TDA1004X_AUTO
, 2, 0);
823 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x0c, 3 << 2);
826 case GUARD_INTERVAL_AUTO
:
827 tda1004x_write_mask(state
, TDA1004X_AUTO
, 2, 2);
828 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x0c, 0 << 2);
835 // set transmission mode
836 switch (fe_params
->u
.ofdm
.transmission_mode
) {
837 case TRANSMISSION_MODE_2K
:
838 tda1004x_write_mask(state
, TDA1004X_AUTO
, 4, 0);
839 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x10, 0 << 4);
842 case TRANSMISSION_MODE_8K
:
843 tda1004x_write_mask(state
, TDA1004X_AUTO
, 4, 0);
844 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x10, 1 << 4);
847 case TRANSMISSION_MODE_AUTO
:
848 tda1004x_write_mask(state
, TDA1004X_AUTO
, 4, 4);
849 tda1004x_write_mask(state
, TDA1004X_IN_CONF1
, 0x10, 0);
857 switch (state
->demod_type
) {
858 case TDA1004X_DEMOD_TDA10045
:
859 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 8, 8);
860 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 8, 0);
863 case TDA1004X_DEMOD_TDA10046
:
864 tda1004x_write_mask(state
, TDA1004X_AUTO
, 0x40, 0x40);
866 tda1004x_write_mask(state
, TDA10046H_AGC_CONF
, 4, 1);
875 static int tda1004x_get_fe(struct dvb_frontend
* fe
, struct dvb_frontend_parameters
*fe_params
)
877 struct tda1004x_state
* state
= fe
->demodulator_priv
;
879 dprintk("%s\n", __FUNCTION__
);
882 fe_params
->inversion
= INVERSION_OFF
;
883 if (tda1004x_read_byte(state
, TDA1004X_CONFC1
) & 0x20)
884 fe_params
->inversion
= INVERSION_ON
;
885 if (state
->config
->invert
)
886 fe_params
->inversion
= fe_params
->inversion
? INVERSION_OFF
: INVERSION_ON
;
889 switch (state
->demod_type
) {
890 case TDA1004X_DEMOD_TDA10045
:
891 switch (tda1004x_read_byte(state
, TDA10045H_WREF_LSB
)) {
893 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
896 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
899 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
903 case TDA1004X_DEMOD_TDA10046
:
904 switch (tda1004x_read_byte(state
, TDA10046H_TIME_WREF1
)) {
907 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
911 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
915 fe_params
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
922 fe_params
->u
.ofdm
.code_rate_HP
=
923 tda1004x_decode_fec(tda1004x_read_byte(state
, TDA1004X_OUT_CONF2
) & 7);
924 fe_params
->u
.ofdm
.code_rate_LP
=
925 tda1004x_decode_fec((tda1004x_read_byte(state
, TDA1004X_OUT_CONF2
) >> 3) & 7);
928 switch (tda1004x_read_byte(state
, TDA1004X_OUT_CONF1
) & 3) {
930 fe_params
->u
.ofdm
.constellation
= QPSK
;
933 fe_params
->u
.ofdm
.constellation
= QAM_16
;
936 fe_params
->u
.ofdm
.constellation
= QAM_64
;
941 fe_params
->u
.ofdm
.transmission_mode
= TRANSMISSION_MODE_2K
;
942 if (tda1004x_read_byte(state
, TDA1004X_OUT_CONF1
) & 0x10)
943 fe_params
->u
.ofdm
.transmission_mode
= TRANSMISSION_MODE_8K
;
946 switch ((tda1004x_read_byte(state
, TDA1004X_OUT_CONF1
) & 0x0c) >> 2) {
948 fe_params
->u
.ofdm
.guard_interval
= GUARD_INTERVAL_1_32
;
951 fe_params
->u
.ofdm
.guard_interval
= GUARD_INTERVAL_1_16
;
954 fe_params
->u
.ofdm
.guard_interval
= GUARD_INTERVAL_1_8
;
957 fe_params
->u
.ofdm
.guard_interval
= GUARD_INTERVAL_1_4
;
962 switch ((tda1004x_read_byte(state
, TDA1004X_OUT_CONF1
) & 0x60) >> 5) {
964 fe_params
->u
.ofdm
.hierarchy_information
= HIERARCHY_NONE
;
967 fe_params
->u
.ofdm
.hierarchy_information
= HIERARCHY_1
;
970 fe_params
->u
.ofdm
.hierarchy_information
= HIERARCHY_2
;
973 fe_params
->u
.ofdm
.hierarchy_information
= HIERARCHY_4
;
980 static int tda1004x_read_status(struct dvb_frontend
* fe
, fe_status_t
* fe_status
)
982 struct tda1004x_state
* state
= fe
->demodulator_priv
;
987 dprintk("%s\n", __FUNCTION__
);
990 status
= tda1004x_read_byte(state
, TDA1004X_STATUS_CD
);
997 *fe_status
|= FE_HAS_SIGNAL
;
999 *fe_status
|= FE_HAS_CARRIER
;
1001 *fe_status
|= FE_HAS_VITERBI
| FE_HAS_SYNC
| FE_HAS_LOCK
;
1003 // if we don't already have VITERBI (i.e. not LOCKED), see if the viterbi
1004 // is getting anything valid
1005 if (!(*fe_status
& FE_HAS_VITERBI
)) {
1007 cber
= tda1004x_read_byte(state
, TDA1004X_CBER_LSB
);
1010 status
= tda1004x_read_byte(state
, TDA1004X_CBER_MSB
);
1013 cber
|= (status
<< 8);
1014 // The address 0x20 should be read to cope with a TDA10046 bug
1015 tda1004x_read_byte(state
, TDA1004X_CBER_RESET
);
1018 *fe_status
|= FE_HAS_VITERBI
;
1021 // if we DO have some valid VITERBI output, but don't already have SYNC
1022 // bytes (i.e. not LOCKED), see if the RS decoder is getting anything valid.
1023 if ((*fe_status
& FE_HAS_VITERBI
) && (!(*fe_status
& FE_HAS_SYNC
))) {
1025 vber
= tda1004x_read_byte(state
, TDA1004X_VBER_LSB
);
1028 status
= tda1004x_read_byte(state
, TDA1004X_VBER_MID
);
1031 vber
|= (status
<< 8);
1032 status
= tda1004x_read_byte(state
, TDA1004X_VBER_MSB
);
1035 vber
|= (status
& 0x0f) << 16;
1036 // The CVBER_LUT should be read to cope with TDA10046 hardware bug
1037 tda1004x_read_byte(state
, TDA1004X_CVBER_LUT
);
1039 // if RS has passed some valid TS packets, then we must be
1040 // getting some SYNC bytes
1042 *fe_status
|= FE_HAS_SYNC
;
1046 dprintk("%s: fe_status=0x%x\n", __FUNCTION__
, *fe_status
);
1050 static int tda1004x_read_signal_strength(struct dvb_frontend
* fe
, u16
* signal
)
1052 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1056 dprintk("%s\n", __FUNCTION__
);
1058 // determine the register to use
1059 switch (state
->demod_type
) {
1060 case TDA1004X_DEMOD_TDA10045
:
1061 reg
= TDA10045H_S_AGC
;
1064 case TDA1004X_DEMOD_TDA10046
:
1065 reg
= TDA10046H_AGC_IF_LEVEL
;
1070 tmp
= tda1004x_read_byte(state
, reg
);
1074 *signal
= (tmp
<< 8) | tmp
;
1075 dprintk("%s: signal=0x%x\n", __FUNCTION__
, *signal
);
1079 static int tda1004x_read_snr(struct dvb_frontend
* fe
, u16
* snr
)
1081 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1084 dprintk("%s\n", __FUNCTION__
);
1087 tmp
= tda1004x_read_byte(state
, TDA1004X_SNR
);
1092 *snr
= ((tmp
<< 8) | tmp
);
1093 dprintk("%s: snr=0x%x\n", __FUNCTION__
, *snr
);
1097 static int tda1004x_read_ucblocks(struct dvb_frontend
* fe
, u32
* ucblocks
)
1099 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1104 dprintk("%s\n", __FUNCTION__
);
1106 // read the UCBLOCKS and reset
1108 tmp
= tda1004x_read_byte(state
, TDA1004X_UNCOR
);
1112 while (counter
++ < 5) {
1113 tda1004x_write_mask(state
, TDA1004X_UNCOR
, 0x80, 0);
1114 tda1004x_write_mask(state
, TDA1004X_UNCOR
, 0x80, 0);
1115 tda1004x_write_mask(state
, TDA1004X_UNCOR
, 0x80, 0);
1117 tmp2
= tda1004x_read_byte(state
, TDA1004X_UNCOR
);
1121 if ((tmp2
< tmp
) || (tmp2
== 0))
1128 *ucblocks
= 0xffffffff;
1130 dprintk("%s: ucblocks=0x%x\n", __FUNCTION__
, *ucblocks
);
1134 static int tda1004x_read_ber(struct dvb_frontend
* fe
, u32
* ber
)
1136 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1139 dprintk("%s\n", __FUNCTION__
);
1142 tmp
= tda1004x_read_byte(state
, TDA1004X_CBER_LSB
);
1146 tmp
= tda1004x_read_byte(state
, TDA1004X_CBER_MSB
);
1150 // The address 0x20 should be read to cope with a TDA10046 bug
1151 tda1004x_read_byte(state
, TDA1004X_CBER_RESET
);
1153 dprintk("%s: ber=0x%x\n", __FUNCTION__
, *ber
);
1157 static int tda1004x_sleep(struct dvb_frontend
* fe
)
1159 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1161 switch (state
->demod_type
) {
1162 case TDA1004X_DEMOD_TDA10045
:
1163 tda1004x_write_mask(state
, TDA1004X_CONFADC1
, 0x10, 0x10);
1166 case TDA1004X_DEMOD_TDA10046
:
1167 /* set outputs to tristate */
1168 tda1004x_write_byteI(state
, TDA10046H_CONF_TRISTATE1
, 0xff);
1169 tda1004x_write_mask(state
, TDA1004X_CONFC4
, 1, 1);
1176 static int tda1004x_i2c_gate_ctrl(struct dvb_frontend
* fe
, int enable
)
1178 struct tda1004x_state
* state
= fe
->demodulator_priv
;
1181 return tda1004x_enable_tuner_i2c(state
);
1183 return tda1004x_disable_tuner_i2c(state
);
1187 static int tda1004x_get_tune_settings(struct dvb_frontend
* fe
, struct dvb_frontend_tune_settings
* fesettings
)
1189 fesettings
->min_delay_ms
= 800;
1190 /* Drift compensation makes no sense for DVB-T */
1191 fesettings
->step_size
= 0;
1192 fesettings
->max_drift
= 0;
1196 static void tda1004x_release(struct dvb_frontend
* fe
)
1198 struct tda1004x_state
*state
= fe
->demodulator_priv
;
1202 static struct dvb_frontend_ops tda10045_ops
= {
1204 .name
= "Philips TDA10045H DVB-T",
1206 .frequency_min
= 51000000,
1207 .frequency_max
= 858000000,
1208 .frequency_stepsize
= 166667,
1210 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
1211 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
1212 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
1213 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
1216 .release
= tda1004x_release
,
1218 .init
= tda10045_init
,
1219 .sleep
= tda1004x_sleep
,
1220 .i2c_gate_ctrl
= tda1004x_i2c_gate_ctrl
,
1222 .set_frontend
= tda1004x_set_fe
,
1223 .get_frontend
= tda1004x_get_fe
,
1224 .get_tune_settings
= tda1004x_get_tune_settings
,
1226 .read_status
= tda1004x_read_status
,
1227 .read_ber
= tda1004x_read_ber
,
1228 .read_signal_strength
= tda1004x_read_signal_strength
,
1229 .read_snr
= tda1004x_read_snr
,
1230 .read_ucblocks
= tda1004x_read_ucblocks
,
1233 struct dvb_frontend
* tda10045_attach(const struct tda1004x_config
* config
,
1234 struct i2c_adapter
* i2c
)
1236 struct tda1004x_state
*state
;
1238 /* allocate memory for the internal state */
1239 state
= kmalloc(sizeof(struct tda1004x_state
), GFP_KERNEL
);
1243 /* setup the state */
1244 state
->config
= config
;
1246 memcpy(&state
->ops
, &tda10045_ops
, sizeof(struct dvb_frontend_ops
));
1247 state
->demod_type
= TDA1004X_DEMOD_TDA10045
;
1249 /* check if the demod is there */
1250 if (tda1004x_read_byte(state
, TDA1004X_CHIPID
) != 0x25) {
1255 /* create dvb_frontend */
1256 state
->frontend
.ops
= &state
->ops
;
1257 state
->frontend
.demodulator_priv
= state
;
1258 return &state
->frontend
;
1261 static struct dvb_frontend_ops tda10046_ops
= {
1263 .name
= "Philips TDA10046H DVB-T",
1265 .frequency_min
= 51000000,
1266 .frequency_max
= 858000000,
1267 .frequency_stepsize
= 166667,
1269 FE_CAN_FEC_1_2
| FE_CAN_FEC_2_3
| FE_CAN_FEC_3_4
|
1270 FE_CAN_FEC_5_6
| FE_CAN_FEC_7_8
| FE_CAN_FEC_AUTO
|
1271 FE_CAN_QPSK
| FE_CAN_QAM_16
| FE_CAN_QAM_64
| FE_CAN_QAM_AUTO
|
1272 FE_CAN_TRANSMISSION_MODE_AUTO
| FE_CAN_GUARD_INTERVAL_AUTO
1275 .release
= tda1004x_release
,
1277 .init
= tda10046_init
,
1278 .sleep
= tda1004x_sleep
,
1280 .set_frontend
= tda1004x_set_fe
,
1281 .get_frontend
= tda1004x_get_fe
,
1282 .get_tune_settings
= tda1004x_get_tune_settings
,
1284 .read_status
= tda1004x_read_status
,
1285 .read_ber
= tda1004x_read_ber
,
1286 .read_signal_strength
= tda1004x_read_signal_strength
,
1287 .read_snr
= tda1004x_read_snr
,
1288 .read_ucblocks
= tda1004x_read_ucblocks
,
1291 struct dvb_frontend
* tda10046_attach(const struct tda1004x_config
* config
,
1292 struct i2c_adapter
* i2c
)
1294 struct tda1004x_state
*state
;
1296 /* allocate memory for the internal state */
1297 state
= kmalloc(sizeof(struct tda1004x_state
), GFP_KERNEL
);
1301 /* setup the state */
1302 state
->config
= config
;
1304 memcpy(&state
->ops
, &tda10046_ops
, sizeof(struct dvb_frontend_ops
));
1305 state
->demod_type
= TDA1004X_DEMOD_TDA10046
;
1307 /* check if the demod is there */
1308 if (tda1004x_read_byte(state
, TDA1004X_CHIPID
) != 0x46) {
1313 /* create dvb_frontend */
1314 state
->frontend
.ops
= &state
->ops
;
1315 state
->frontend
.demodulator_priv
= state
;
1316 return &state
->frontend
;
1319 module_param(debug
, int, 0644);
1320 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
1322 MODULE_DESCRIPTION("Philips TDA10045H & TDA10046H DVB-T Demodulator");
1323 MODULE_AUTHOR("Andrew de Quincey & Robert Schlabbach");
1324 MODULE_LICENSE("GPL");
1326 EXPORT_SYMBOL(tda10045_attach
);
1327 EXPORT_SYMBOL(tda10046_attach
);
1328 EXPORT_SYMBOL(tda1004x_write_byte
);