2 * Driver for Silicon Labs Si2161 DVB-T and Si2165 DVB-C/-T Demodulator
4 * Copyright (C) 2013-2014 Matthias Schwarzott <zzam@gentoo.org>
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
14 * GNU General Public License for more details.
17 * http://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
20 #include <linux/delay.h>
21 #include <linux/errno.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/string.h>
26 #include <linux/slab.h>
27 #include <linux/firmware.h>
29 #include "dvb_frontend.h"
31 #include "si2165_priv.h"
35 * Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
38 * Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
39 * uses 24 MHz clock provided by tuner
43 struct i2c_adapter
*i2c
;
45 struct dvb_frontend fe
;
47 struct si2165_config config
;
52 /* calculated by xtal and div settings */
62 #define DEBUG_OTHER 0x01
63 #define DEBUG_I2C_WRITE 0x02
64 #define DEBUG_I2C_READ 0x04
65 #define DEBUG_REG_READ 0x08
66 #define DEBUG_REG_WRITE 0x10
67 #define DEBUG_FW_LOAD 0x20
69 static int debug
= 0x00;
71 #define dprintk(args...) \
73 if (debug & DEBUG_OTHER) \
74 printk(KERN_DEBUG "si2165: " args); \
77 #define deb_i2c_write(args...) \
79 if (debug & DEBUG_I2C_WRITE) \
80 printk(KERN_DEBUG "si2165: i2c write: " args); \
83 #define deb_i2c_read(args...) \
85 if (debug & DEBUG_I2C_READ) \
86 printk(KERN_DEBUG "si2165: i2c read: " args); \
89 #define deb_readreg(args...) \
91 if (debug & DEBUG_REG_READ) \
92 printk(KERN_DEBUG "si2165: reg read: " args); \
95 #define deb_writereg(args...) \
97 if (debug & DEBUG_REG_WRITE) \
98 printk(KERN_DEBUG "si2165: reg write: " args); \
101 #define deb_fw_load(args...) \
103 if (debug & DEBUG_FW_LOAD) \
104 printk(KERN_DEBUG "si2165: fw load: " args); \
107 static int si2165_write(struct si2165_state
*state
, const u16 reg
,
108 const u8
*src
, const int count
)
112 u8 buf
[2 + 4]; /* write a maximum of 4 bytes of data */
114 if (count
+ 2 > sizeof(buf
)) {
115 dev_warn(&state
->i2c
->dev
,
116 "%s: i2c wr reg=%04x: count=%d is too big!\n",
117 KBUILD_MODNAME
, reg
, count
);
122 memcpy(buf
+ 2, src
, count
);
124 msg
.addr
= state
->config
.i2c_addr
;
129 if (debug
& DEBUG_I2C_WRITE
)
130 deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg
, count
, src
);
132 ret
= i2c_transfer(state
->i2c
, &msg
, 1);
135 dev_err(&state
->i2c
->dev
, "%s: ret == %d\n", __func__
, ret
);
145 static int si2165_read(struct si2165_state
*state
,
146 const u16 reg
, u8
*val
, const int count
)
149 u8 reg_buf
[] = { reg
>> 8, reg
& 0xff };
150 struct i2c_msg msg
[] = {
151 { .addr
= state
->config
.i2c_addr
,
152 .flags
= 0, .buf
= reg_buf
, .len
= 2 },
153 { .addr
= state
->config
.i2c_addr
,
154 .flags
= I2C_M_RD
, .buf
= val
, .len
= count
},
157 ret
= i2c_transfer(state
->i2c
, msg
, 2);
160 dev_err(&state
->i2c
->dev
, "%s: error (addr %02x reg %04x error (ret == %i)\n",
161 __func__
, state
->config
.i2c_addr
, reg
, ret
);
168 if (debug
& DEBUG_I2C_READ
)
169 deb_i2c_read("reg: 0x%04x, data: %*ph\n", reg
, count
, val
);
174 static int si2165_readreg8(struct si2165_state
*state
,
175 const u16 reg
, u8
*val
)
179 ret
= si2165_read(state
, reg
, val
, 1);
180 deb_readreg("R(0x%04x)=0x%02x\n", reg
, *val
);
184 static int si2165_readreg16(struct si2165_state
*state
,
185 const u16 reg
, u16
*val
)
189 int ret
= si2165_read(state
, reg
, buf
, 2);
190 *val
= buf
[0] | buf
[1] << 8;
191 deb_readreg("R(0x%04x)=0x%04x\n", reg
, *val
);
195 static int si2165_writereg8(struct si2165_state
*state
, const u16 reg
, u8 val
)
197 return si2165_write(state
, reg
, &val
, 1);
200 static int si2165_writereg16(struct si2165_state
*state
, const u16 reg
, u16 val
)
202 u8 buf
[2] = { val
& 0xff, (val
>> 8) & 0xff };
204 return si2165_write(state
, reg
, buf
, 2);
207 static int si2165_writereg24(struct si2165_state
*state
, const u16 reg
, u32 val
)
209 u8 buf
[3] = { val
& 0xff, (val
>> 8) & 0xff, (val
>> 16) & 0xff };
211 return si2165_write(state
, reg
, buf
, 3);
214 static int si2165_writereg32(struct si2165_state
*state
, const u16 reg
, u32 val
)
222 return si2165_write(state
, reg
, buf
, 4);
225 static int si2165_writereg_mask8(struct si2165_state
*state
, const u16 reg
,
232 ret
= si2165_readreg8(state
, reg
, &tmp
);
241 ret
= si2165_writereg8(state
, reg
, val
);
246 #define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
247 struct si2165_reg_value_pair
{
252 static int si2165_write_reg_list(struct si2165_state
*state
,
253 const struct si2165_reg_value_pair
*regs
,
259 for (i
= 0; i
< count
; i
++) {
260 ret
= si2165_writereg8(state
, regs
[i
].reg
, regs
[i
].val
);
267 static int si2165_get_tune_settings(struct dvb_frontend
*fe
,
268 struct dvb_frontend_tune_settings
*s
)
270 s
->min_delay_ms
= 1000;
274 static int si2165_init_pll(struct si2165_state
*state
)
276 u32 ref_freq_Hz
= state
->config
.ref_freq_Hz
;
277 u8 divr
= 1; /* 1..7 */
278 u8 divp
= 1; /* only 1 or 4 */
279 u8 divn
= 56; /* 1..63 */
285 * hardcoded values can be deleted if calculation is verified
286 * or it yields the same values as the windows driver
288 switch (ref_freq_Hz
) {
298 /* ref_freq / divr must be between 4 and 16 MHz */
299 if (ref_freq_Hz
> 16000000u)
303 * now select divn and divp such that
304 * fvco is in 1624..1824 MHz
306 if (1624000000u * divr
> ref_freq_Hz
* 2u * 63u)
309 /* is this already correct regarding rounding? */
310 divn
= 1624000000u * divr
/ (ref_freq_Hz
* 2u * divp
);
314 /* adc_clk and sys_clk depend on xtal and pll settings */
315 state
->fvco_hz
= ref_freq_Hz
/ divr
317 state
->adc_clk
= state
->fvco_hz
/ (divm
* 4u);
318 state
->sys_clk
= state
->fvco_hz
/ (divl
* 2u);
320 /* write pll registers 0x00a0..0x00a3 at once */
323 buf
[2] = (divn
& 0x3f) | ((divp
== 1) ? 0x40 : 0x00) | 0x80;
325 return si2165_write(state
, 0x00a0, buf
, 4);
328 static int si2165_adjust_pll_divl(struct si2165_state
*state
, u8 divl
)
330 state
->sys_clk
= state
->fvco_hz
/ (divl
* 2u);
331 return si2165_writereg8(state
, 0x00a0, divl
); /* pll_divl */
334 static u32
si2165_get_fe_clk(struct si2165_state
*state
)
336 /* assume Oversampling mode Ovr4 is used */
337 return state
->adc_clk
;
340 static int si2165_wait_init_done(struct si2165_state
*state
)
346 for (i
= 0; i
< 3; ++i
) {
347 si2165_readreg8(state
, 0x0054, &val
);
350 usleep_range(1000, 50000);
352 dev_err(&state
->i2c
->dev
, "%s: init_done was not set\n",
357 static int si2165_upload_firmware_block(struct si2165_state
*state
,
358 const u8
*data
, u32 len
, u32
*poffset
, u32 block_count
)
361 u8 buf_ctrl
[4] = { 0x00, 0x00, 0x00, 0xc0 };
364 u32 offset
= poffset
? *poffset
: 0;
372 "si2165_upload_firmware_block called with len=0x%x offset=0x%x blockcount=0x%x\n",
373 len
, offset
, block_count
);
374 while (offset
+12 <= len
&& cur_block
< block_count
) {
376 "si2165_upload_firmware_block in while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
377 len
, offset
, cur_block
, block_count
);
378 wordcount
= data
[offset
];
379 if (wordcount
< 1 || data
[offset
+1] ||
380 data
[offset
+2] || data
[offset
+3]) {
381 dev_warn(&state
->i2c
->dev
,
382 "%s: bad fw data[0..3] = %*ph\n",
383 KBUILD_MODNAME
, 4, data
);
387 if (offset
+ 8 + wordcount
* 4 > len
) {
388 dev_warn(&state
->i2c
->dev
,
389 "%s: len is too small for block len=%d, wordcount=%d\n",
390 KBUILD_MODNAME
, len
, wordcount
);
394 buf_ctrl
[0] = wordcount
- 1;
396 ret
= si2165_write(state
, 0x0364, buf_ctrl
, 4);
399 ret
= si2165_write(state
, 0x0368, data
+offset
+4, 4);
405 while (wordcount
> 0) {
406 ret
= si2165_write(state
, 0x36c, data
+offset
, 4);
416 "si2165_upload_firmware_block after while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
417 len
, offset
, cur_block
, block_count
);
422 deb_fw_load("si2165_upload_firmware_block returned offset=0x%x\n",
430 static int si2165_upload_firmware(struct si2165_state
*state
)
437 const struct firmware
*fw
= NULL
;
446 switch (state
->chip_revcode
) {
447 case 0x03: /* revision D */
448 fw_file
= SI2165_FIRMWARE_REV_D
;
451 dev_info(&state
->i2c
->dev
, "%s: no firmware file for revision=%d\n",
452 KBUILD_MODNAME
, state
->chip_revcode
);
456 /* request the firmware, this will block and timeout */
457 ret
= request_firmware(&fw
, fw_file
, state
->i2c
->dev
.parent
);
459 dev_warn(&state
->i2c
->dev
, "%s: firmware file '%s' not found\n",
460 KBUILD_MODNAME
, fw_file
);
467 dev_info(&state
->i2c
->dev
, "%s: downloading firmware from file '%s' size=%d\n",
468 KBUILD_MODNAME
, fw_file
, len
);
471 dev_warn(&state
->i2c
->dev
, "%s: firmware size is not multiple of 4\n",
477 /* check header (8 bytes) */
479 dev_warn(&state
->i2c
->dev
, "%s: firmware header is missing\n",
485 if (data
[0] != 1 || data
[1] != 0) {
486 dev_warn(&state
->i2c
->dev
, "%s: firmware file version is wrong\n",
492 patch_version
= data
[2];
493 block_count
= data
[4];
494 crc_expected
= data
[7] << 8 | data
[6];
496 /* start uploading fw */
497 /* boot/wdog status */
498 ret
= si2165_writereg8(state
, 0x0341, 0x00);
502 ret
= si2165_writereg8(state
, 0x00c0, 0x00);
505 /* boot/wdog status */
506 ret
= si2165_readreg8(state
, 0x0341, val
);
510 /* enable reset on error */
511 ret
= si2165_readreg8(state
, 0x035c, val
);
514 ret
= si2165_readreg8(state
, 0x035c, val
);
517 ret
= si2165_writereg8(state
, 0x035c, 0x02);
521 /* start right after the header */
524 dev_info(&state
->i2c
->dev
, "%s: si2165_upload_firmware extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
525 KBUILD_MODNAME
, patch_version
, block_count
, crc_expected
);
527 ret
= si2165_upload_firmware_block(state
, data
, len
, &offset
, 1);
531 ret
= si2165_writereg8(state
, 0x0344, patch_version
);
536 ret
= si2165_writereg8(state
, 0x0379, 0x01);
540 ret
= si2165_upload_firmware_block(state
, data
, len
,
541 &offset
, block_count
);
543 dev_err(&state
->i2c
->dev
,
544 "%s: firmware could not be uploaded\n",
550 ret
= si2165_readreg16(state
, 0x037a, &val16
);
554 if (val16
!= crc_expected
) {
555 dev_err(&state
->i2c
->dev
,
556 "%s: firmware crc mismatch %04x != %04x\n",
557 KBUILD_MODNAME
, val16
, crc_expected
);
562 ret
= si2165_upload_firmware_block(state
, data
, len
, &offset
, 5);
567 dev_err(&state
->i2c
->dev
,
568 "%s: firmware len mismatch %04x != %04x\n",
569 KBUILD_MODNAME
, len
, offset
);
574 /* reset watchdog error register */
575 ret
= si2165_writereg_mask8(state
, 0x0341, 0x02, 0x02);
579 /* enable reset on error */
580 ret
= si2165_writereg_mask8(state
, 0x035c, 0x01, 0x01);
584 dev_info(&state
->i2c
->dev
, "%s: fw load finished\n", KBUILD_MODNAME
);
587 state
->firmware_loaded
= true;
590 release_firmware(fw
);
597 static int si2165_init(struct dvb_frontend
*fe
)
600 struct si2165_state
*state
= fe
->demodulator_priv
;
602 u8 patch_version
= 0x00;
604 dprintk("%s: called\n", __func__
);
607 ret
= si2165_writereg8(state
, 0x0000, state
->config
.chip_mode
);
610 /* dsp_clock_enable */
611 ret
= si2165_writereg8(state
, 0x0104, 0x01);
614 ret
= si2165_readreg8(state
, 0x0000, &val
); /* verify chip_mode */
617 if (val
!= state
->config
.chip_mode
) {
618 dev_err(&state
->i2c
->dev
, "%s: could not set chip_mode\n",
624 ret
= si2165_writereg8(state
, 0x018b, 0x00);
627 ret
= si2165_writereg8(state
, 0x0190, 0x01);
630 ret
= si2165_writereg8(state
, 0x0170, 0x00);
633 ret
= si2165_writereg8(state
, 0x0171, 0x07);
637 ret
= si2165_writereg8(state
, 0x0646, 0x00);
640 ret
= si2165_writereg8(state
, 0x0641, 0x00);
644 ret
= si2165_init_pll(state
);
648 /* enable chip_init */
649 ret
= si2165_writereg8(state
, 0x0050, 0x01);
653 ret
= si2165_writereg8(state
, 0x0096, 0x01);
656 ret
= si2165_wait_init_done(state
);
660 /* disable chip_init */
661 ret
= si2165_writereg8(state
, 0x0050, 0x00);
666 ret
= si2165_writereg16(state
, 0x0470, 0x7530);
670 ret
= si2165_readreg8(state
, 0x0344, &patch_version
);
674 ret
= si2165_writereg8(state
, 0x00cb, 0x00);
679 ret
= si2165_writereg32(state
, 0x0348, 0xf4000000);
682 /* boot/wdog status */
683 ret
= si2165_readreg8(state
, 0x0341, &val
);
687 if (patch_version
== 0x00) {
688 ret
= si2165_upload_firmware(state
);
693 /* ts output config */
694 ret
= si2165_writereg8(state
, 0x04e4, 0x20);
697 ret
= si2165_writereg16(state
, 0x04ef, 0x00fe);
700 ret
= si2165_writereg24(state
, 0x04f4, 0x555555);
703 ret
= si2165_writereg8(state
, 0x04e5, 0x01);
712 static int si2165_sleep(struct dvb_frontend
*fe
)
715 struct si2165_state
*state
= fe
->demodulator_priv
;
717 /* dsp clock disable */
718 ret
= si2165_writereg8(state
, 0x0104, 0x00);
722 ret
= si2165_writereg8(state
, 0x0000, SI2165_MODE_OFF
);
728 static int si2165_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
732 struct si2165_state
*state
= fe
->demodulator_priv
;
734 if (!state
->has_dvbt
)
738 ret
= si2165_readreg8(state
, 0x4e0, &fec_lock
);
742 if (fec_lock
& 0x01) {
743 *status
|= FE_HAS_SIGNAL
;
744 *status
|= FE_HAS_CARRIER
;
745 *status
|= FE_HAS_VITERBI
;
746 *status
|= FE_HAS_SYNC
;
747 *status
|= FE_HAS_LOCK
;
753 static int si2165_set_oversamp(struct si2165_state
*state
, u32 dvb_rate
)
758 oversamp
= si2165_get_fe_clk(state
);
760 do_div(oversamp
, dvb_rate
);
761 reg_value
= oversamp
& 0x3fffffff;
763 dprintk("%s: Write oversamp=%#x\n", __func__
, reg_value
);
764 return si2165_writereg32(state
, 0x00e4, reg_value
);
767 static int si2165_set_if_freq_shift(struct si2165_state
*state
)
769 struct dvb_frontend
*fe
= &state
->fe
;
772 u32 fe_clk
= si2165_get_fe_clk(state
);
775 if (!fe
->ops
.tuner_ops
.get_if_frequency
) {
776 dev_err(&state
->i2c
->dev
,
777 "%s: Error: get_if_frequency() not defined at tuner. Can't work without it!\n",
782 fe
->ops
.tuner_ops
.get_if_frequency(fe
, &IF
);
784 if_freq_shift
<<= 29;
786 do_div(if_freq_shift
, fe_clk
);
787 reg_value
= (s32
)if_freq_shift
;
789 if (state
->config
.inversion
)
790 reg_value
= -reg_value
;
792 reg_value
= reg_value
& 0x1fffffff;
794 /* if_freq_shift, usbdump contained 0x023ee08f; */
795 return si2165_writereg32(state
, 0x00e8, reg_value
);
798 static const struct si2165_reg_value_pair dvbt_regs
[] = {
799 /* standard = DVB-T */
802 /* impulsive_noise_remover */
815 /* freq_sync_range */
816 REG16(0x030c, 0x0064),
821 static int si2165_set_frontend_dvbt(struct dvb_frontend
*fe
)
824 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
825 struct si2165_state
*state
= fe
->demodulator_priv
;
829 dprintk("%s: called\n", __func__
);
831 if (!state
->has_dvbt
)
834 if (p
->bandwidth_hz
> 0) {
835 dvb_rate
= p
->bandwidth_hz
* 8 / 7;
836 bw10k
= p
->bandwidth_hz
/ 10000;
838 dvb_rate
= 8 * 8 / 7;
842 ret
= si2165_adjust_pll_divl(state
, 12);
846 /* bandwidth in 10KHz steps */
847 ret
= si2165_writereg16(state
, 0x0308, bw10k
);
850 ret
= si2165_set_oversamp(state
, dvb_rate
);
854 ret
= si2165_write_reg_list(state
, dvbt_regs
, ARRAY_SIZE(dvbt_regs
));
861 static const struct si2165_reg_value_pair dvbc_regs
[] = {
862 /* standard = DVB-C */
881 REG16(0x0350, 0x3e80),
885 REG16(0x024c, 0x0000),
886 REG16(0x027c, 0x0000),
892 static int si2165_set_frontend_dvbc(struct dvb_frontend
*fe
)
894 struct si2165_state
*state
= fe
->demodulator_priv
;
896 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
897 const u32 dvb_rate
= p
->symbol_rate
;
898 const u32 bw_hz
= p
->bandwidth_hz
;
900 if (!state
->has_dvbc
)
906 ret
= si2165_adjust_pll_divl(state
, 14);
911 ret
= si2165_set_oversamp(state
, dvb_rate
);
915 ret
= si2165_writereg32(state
, 0x00c4, bw_hz
);
919 ret
= si2165_write_reg_list(state
, dvbc_regs
, ARRAY_SIZE(dvbc_regs
));
926 static const struct si2165_reg_value_pair agc_rewrite
[] = {
934 static int si2165_set_frontend(struct dvb_frontend
*fe
)
936 struct si2165_state
*state
= fe
->demodulator_priv
;
937 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
938 u32 delsys
= p
->delivery_system
;
942 /* initial setting of if freq shift */
943 ret
= si2165_set_if_freq_shift(state
);
949 ret
= si2165_set_frontend_dvbt(fe
);
953 case SYS_DVBC_ANNEX_A
:
954 ret
= si2165_set_frontend_dvbc(fe
);
963 ret
= si2165_writereg32(state
, 0x0348, 0xf4000000);
967 if (fe
->ops
.tuner_ops
.set_params
)
968 fe
->ops
.tuner_ops
.set_params(fe
);
970 /* recalc if_freq_shift if IF might has changed */
971 ret
= si2165_set_if_freq_shift(state
);
975 /* boot/wdog status */
976 ret
= si2165_readreg8(state
, 0x0341, val
);
979 ret
= si2165_writereg8(state
, 0x0341, 0x00);
984 ret
= si2165_writereg8(state
, 0x00c0, 0x00);
988 ret
= si2165_writereg32(state
, 0x0384, 0x00000000);
992 /* write adc values after each reset*/
993 ret
= si2165_write_reg_list(state
, agc_rewrite
,
994 ARRAY_SIZE(agc_rewrite
));
999 ret
= si2165_writereg8(state
, 0x02e0, 0x01);
1002 /* boot/wdog status */
1003 ret
= si2165_readreg8(state
, 0x0341, val
);
1010 static void si2165_release(struct dvb_frontend
*fe
)
1012 struct si2165_state
*state
= fe
->demodulator_priv
;
1014 dprintk("%s: called\n", __func__
);
1018 static struct dvb_frontend_ops si2165_ops
= {
1020 .name
= "Silicon Labs ",
1022 .symbol_rate_min
= 1000000,
1023 .symbol_rate_max
= 7200000,
1025 .frequency_stepsize
= 166667,
1026 .caps
= FE_CAN_FEC_1_2
|
1039 FE_CAN_GUARD_INTERVAL_AUTO
|
1040 FE_CAN_HIERARCHY_AUTO
|
1042 FE_CAN_TRANSMISSION_MODE_AUTO
|
1046 .get_tune_settings
= si2165_get_tune_settings
,
1048 .init
= si2165_init
,
1049 .sleep
= si2165_sleep
,
1051 .set_frontend
= si2165_set_frontend
,
1052 .read_status
= si2165_read_status
,
1054 .release
= si2165_release
,
1057 struct dvb_frontend
*si2165_attach(const struct si2165_config
*config
,
1058 struct i2c_adapter
*i2c
)
1060 struct si2165_state
*state
= NULL
;
1065 const char *chip_name
;
1067 if (config
== NULL
|| i2c
== NULL
)
1070 /* allocate memory for the internal state */
1071 state
= kzalloc(sizeof(struct si2165_state
), GFP_KERNEL
);
1075 /* setup the state */
1077 state
->config
= *config
;
1079 if (state
->config
.ref_freq_Hz
< 4000000
1080 || state
->config
.ref_freq_Hz
> 27000000) {
1081 dev_err(&state
->i2c
->dev
, "%s: ref_freq of %d Hz not supported by this driver\n",
1082 KBUILD_MODNAME
, state
->config
.ref_freq_Hz
);
1086 /* create dvb_frontend */
1087 memcpy(&state
->fe
.ops
, &si2165_ops
,
1088 sizeof(struct dvb_frontend_ops
));
1089 state
->fe
.demodulator_priv
= state
;
1092 io_ret
= si2165_writereg8(state
, 0x0000, state
->config
.chip_mode
);
1096 io_ret
= si2165_readreg8(state
, 0x0000, &val
);
1099 if (val
!= state
->config
.chip_mode
)
1102 io_ret
= si2165_readreg8(state
, 0x0023, &state
->chip_revcode
);
1106 io_ret
= si2165_readreg8(state
, 0x0118, &state
->chip_type
);
1111 io_ret
= si2165_writereg8(state
, 0x0000, SI2165_MODE_OFF
);
1115 if (state
->chip_revcode
< 26)
1116 rev_char
= 'A' + state
->chip_revcode
;
1120 switch (state
->chip_type
) {
1122 chip_name
= "Si2161";
1123 state
->has_dvbt
= true;
1126 chip_name
= "Si2165";
1127 state
->has_dvbt
= true;
1128 state
->has_dvbc
= true;
1131 dev_err(&state
->i2c
->dev
, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
1132 KBUILD_MODNAME
, state
->chip_type
, state
->chip_revcode
);
1136 dev_info(&state
->i2c
->dev
,
1137 "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
1138 KBUILD_MODNAME
, chip_name
, rev_char
, state
->chip_type
,
1139 state
->chip_revcode
);
1141 strlcat(state
->fe
.ops
.info
.name
, chip_name
,
1142 sizeof(state
->fe
.ops
.info
.name
));
1145 if (state
->has_dvbt
) {
1146 state
->fe
.ops
.delsys
[n
++] = SYS_DVBT
;
1147 strlcat(state
->fe
.ops
.info
.name
, " DVB-T",
1148 sizeof(state
->fe
.ops
.info
.name
));
1150 if (state
->has_dvbc
) {
1151 state
->fe
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_A
;
1152 strlcat(state
->fe
.ops
.info
.name
, " DVB-C",
1153 sizeof(state
->fe
.ops
.info
.name
));
1162 EXPORT_SYMBOL(si2165_attach
);
1164 module_param(debug
, int, 0644);
1165 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
1167 MODULE_DESCRIPTION("Silicon Labs Si2165 DVB-C/-T Demodulator driver");
1168 MODULE_AUTHOR("Matthias Schwarzott <zzam@gentoo.org>");
1169 MODULE_LICENSE("GPL");
1170 MODULE_FIRMWARE(SI2165_FIRMWARE_REV_D
);