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>
28 #include <linux/regmap.h>
30 #include "dvb_frontend.h"
32 #include "si2165_priv.h"
36 * Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
39 * Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
40 * uses 24 MHz clock provided by tuner
44 struct i2c_client
*client
;
46 struct regmap
*regmap
;
48 struct dvb_frontend fe
;
50 struct si2165_config config
;
55 /* calculated by xtal and div settings */
65 #define DEBUG_OTHER 0x01
66 #define DEBUG_I2C_WRITE 0x02
67 #define DEBUG_I2C_READ 0x04
68 #define DEBUG_REG_READ 0x08
69 #define DEBUG_REG_WRITE 0x10
70 #define DEBUG_FW_LOAD 0x20
72 static int debug
= 0x00;
74 #define dprintk(args...) \
76 if (debug & DEBUG_OTHER) \
77 printk(KERN_DEBUG "si2165: " args); \
80 #define deb_i2c_write(args...) \
82 if (debug & DEBUG_I2C_WRITE) \
83 printk(KERN_DEBUG "si2165: i2c write: " args); \
86 #define deb_i2c_read(args...) \
88 if (debug & DEBUG_I2C_READ) \
89 printk(KERN_DEBUG "si2165: i2c read: " args); \
92 #define deb_readreg(args...) \
94 if (debug & DEBUG_REG_READ) \
95 printk(KERN_DEBUG "si2165: reg read: " args); \
98 #define deb_writereg(args...) \
100 if (debug & DEBUG_REG_WRITE) \
101 printk(KERN_DEBUG "si2165: reg write: " args); \
104 #define deb_fw_load(args...) \
106 if (debug & DEBUG_FW_LOAD) \
107 printk(KERN_DEBUG "si2165: fw load: " args); \
110 static int si2165_write(struct si2165_state
*state
, const u16 reg
,
111 const u8
*src
, const int count
)
115 if (debug
& DEBUG_I2C_WRITE
)
116 deb_i2c_write("reg: 0x%04x, data: %*ph\n", reg
, count
, src
);
118 ret
= regmap_bulk_write(state
->regmap
, reg
, src
, count
);
121 dev_err(&state
->client
->dev
, "%s: ret == %d\n", __func__
, ret
);
126 static int si2165_read(struct si2165_state
*state
,
127 const u16 reg
, u8
*val
, const int count
)
129 int ret
= regmap_bulk_read(state
->regmap
, reg
, val
, count
);
132 dev_err(&state
->client
->dev
, "%s: error (addr %02x reg %04x error (ret == %i)\n",
133 __func__
, state
->config
.i2c_addr
, reg
, ret
);
137 if (debug
& DEBUG_I2C_READ
)
138 deb_i2c_read("reg: 0x%04x, data: %*ph\n", reg
, count
, val
);
143 static int si2165_readreg8(struct si2165_state
*state
,
144 const u16 reg
, u8
*val
)
146 unsigned int val_tmp
;
147 int ret
= regmap_read(state
->regmap
, reg
, &val_tmp
);
149 deb_readreg("R(0x%04x)=0x%02x\n", reg
, *val
);
153 static int si2165_readreg16(struct si2165_state
*state
,
154 const u16 reg
, u16
*val
)
158 int ret
= si2165_read(state
, reg
, buf
, 2);
159 *val
= buf
[0] | buf
[1] << 8;
160 deb_readreg("R(0x%04x)=0x%04x\n", reg
, *val
);
164 static int si2165_writereg8(struct si2165_state
*state
, const u16 reg
, u8 val
)
166 return regmap_write(state
->regmap
, reg
, val
);
169 static int si2165_writereg16(struct si2165_state
*state
, const u16 reg
, u16 val
)
171 u8 buf
[2] = { val
& 0xff, (val
>> 8) & 0xff };
173 return si2165_write(state
, reg
, buf
, 2);
176 static int si2165_writereg24(struct si2165_state
*state
, const u16 reg
, u32 val
)
178 u8 buf
[3] = { val
& 0xff, (val
>> 8) & 0xff, (val
>> 16) & 0xff };
180 return si2165_write(state
, reg
, buf
, 3);
183 static int si2165_writereg32(struct si2165_state
*state
, const u16 reg
, u32 val
)
191 return si2165_write(state
, reg
, buf
, 4);
194 static int si2165_writereg_mask8(struct si2165_state
*state
, const u16 reg
,
199 int ret
= si2165_readreg8(state
, reg
, &tmp
);
208 return si2165_writereg8(state
, reg
, val
);
211 #define REG16(reg, val) { (reg), (val) & 0xff }, { (reg)+1, (val)>>8 & 0xff }
212 struct si2165_reg_value_pair
{
217 static int si2165_write_reg_list(struct si2165_state
*state
,
218 const struct si2165_reg_value_pair
*regs
,
224 for (i
= 0; i
< count
; i
++) {
225 ret
= si2165_writereg8(state
, regs
[i
].reg
, regs
[i
].val
);
232 static int si2165_get_tune_settings(struct dvb_frontend
*fe
,
233 struct dvb_frontend_tune_settings
*s
)
235 s
->min_delay_ms
= 1000;
239 static int si2165_init_pll(struct si2165_state
*state
)
241 u32 ref_freq_Hz
= state
->config
.ref_freq_Hz
;
242 u8 divr
= 1; /* 1..7 */
243 u8 divp
= 1; /* only 1 or 4 */
244 u8 divn
= 56; /* 1..63 */
250 * hardcoded values can be deleted if calculation is verified
251 * or it yields the same values as the windows driver
253 switch (ref_freq_Hz
) {
263 /* ref_freq / divr must be between 4 and 16 MHz */
264 if (ref_freq_Hz
> 16000000u)
268 * now select divn and divp such that
269 * fvco is in 1624..1824 MHz
271 if (1624000000u * divr
> ref_freq_Hz
* 2u * 63u)
274 /* is this already correct regarding rounding? */
275 divn
= 1624000000u * divr
/ (ref_freq_Hz
* 2u * divp
);
279 /* adc_clk and sys_clk depend on xtal and pll settings */
280 state
->fvco_hz
= ref_freq_Hz
/ divr
282 state
->adc_clk
= state
->fvco_hz
/ (divm
* 4u);
283 state
->sys_clk
= state
->fvco_hz
/ (divl
* 2u);
285 /* write pll registers 0x00a0..0x00a3 at once */
288 buf
[2] = (divn
& 0x3f) | ((divp
== 1) ? 0x40 : 0x00) | 0x80;
290 return si2165_write(state
, 0x00a0, buf
, 4);
293 static int si2165_adjust_pll_divl(struct si2165_state
*state
, u8 divl
)
295 state
->sys_clk
= state
->fvco_hz
/ (divl
* 2u);
296 return si2165_writereg8(state
, 0x00a0, divl
); /* pll_divl */
299 static u32
si2165_get_fe_clk(struct si2165_state
*state
)
301 /* assume Oversampling mode Ovr4 is used */
302 return state
->adc_clk
;
305 static int si2165_wait_init_done(struct si2165_state
*state
)
311 for (i
= 0; i
< 3; ++i
) {
312 si2165_readreg8(state
, 0x0054, &val
);
315 usleep_range(1000, 50000);
317 dev_err(&state
->client
->dev
, "%s: init_done was not set\n",
322 static int si2165_upload_firmware_block(struct si2165_state
*state
,
323 const u8
*data
, u32 len
, u32
*poffset
, u32 block_count
)
326 u8 buf_ctrl
[4] = { 0x00, 0x00, 0x00, 0xc0 };
329 u32 offset
= poffset
? *poffset
: 0;
337 "si2165_upload_firmware_block called with len=0x%x offset=0x%x blockcount=0x%x\n",
338 len
, offset
, block_count
);
339 while (offset
+12 <= len
&& cur_block
< block_count
) {
341 "si2165_upload_firmware_block in while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
342 len
, offset
, cur_block
, block_count
);
343 wordcount
= data
[offset
];
344 if (wordcount
< 1 || data
[offset
+1] ||
345 data
[offset
+2] || data
[offset
+3]) {
346 dev_warn(&state
->client
->dev
,
347 "%s: bad fw data[0..3] = %*ph\n",
348 KBUILD_MODNAME
, 4, data
);
352 if (offset
+ 8 + wordcount
* 4 > len
) {
353 dev_warn(&state
->client
->dev
,
354 "%s: len is too small for block len=%d, wordcount=%d\n",
355 KBUILD_MODNAME
, len
, wordcount
);
359 buf_ctrl
[0] = wordcount
- 1;
361 ret
= si2165_write(state
, 0x0364, buf_ctrl
, 4);
364 ret
= si2165_write(state
, 0x0368, data
+offset
+4, 4);
370 while (wordcount
> 0) {
371 ret
= si2165_write(state
, 0x36c, data
+offset
, 4);
381 "si2165_upload_firmware_block after while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
382 len
, offset
, cur_block
, block_count
);
387 deb_fw_load("si2165_upload_firmware_block returned offset=0x%x\n",
395 static int si2165_upload_firmware(struct si2165_state
*state
)
402 const struct firmware
*fw
= NULL
;
411 switch (state
->chip_revcode
) {
412 case 0x03: /* revision D */
413 fw_file
= SI2165_FIRMWARE_REV_D
;
416 dev_info(&state
->client
->dev
, "%s: no firmware file for revision=%d\n",
417 KBUILD_MODNAME
, state
->chip_revcode
);
421 /* request the firmware, this will block and timeout */
422 ret
= request_firmware(&fw
, fw_file
, &state
->client
->dev
);
424 dev_warn(&state
->client
->dev
, "%s: firmware file '%s' not found\n",
425 KBUILD_MODNAME
, fw_file
);
432 dev_info(&state
->client
->dev
, "%s: downloading firmware from file '%s' size=%d\n",
433 KBUILD_MODNAME
, fw_file
, len
);
436 dev_warn(&state
->client
->dev
, "%s: firmware size is not multiple of 4\n",
442 /* check header (8 bytes) */
444 dev_warn(&state
->client
->dev
, "%s: firmware header is missing\n",
450 if (data
[0] != 1 || data
[1] != 0) {
451 dev_warn(&state
->client
->dev
, "%s: firmware file version is wrong\n",
457 patch_version
= data
[2];
458 block_count
= data
[4];
459 crc_expected
= data
[7] << 8 | data
[6];
461 /* start uploading fw */
462 /* boot/wdog status */
463 ret
= si2165_writereg8(state
, 0x0341, 0x00);
467 ret
= si2165_writereg8(state
, 0x00c0, 0x00);
470 /* boot/wdog status */
471 ret
= si2165_readreg8(state
, 0x0341, val
);
475 /* enable reset on error */
476 ret
= si2165_readreg8(state
, 0x035c, val
);
479 ret
= si2165_readreg8(state
, 0x035c, val
);
482 ret
= si2165_writereg8(state
, 0x035c, 0x02);
486 /* start right after the header */
489 dev_info(&state
->client
->dev
, "%s: si2165_upload_firmware extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
490 KBUILD_MODNAME
, patch_version
, block_count
, crc_expected
);
492 ret
= si2165_upload_firmware_block(state
, data
, len
, &offset
, 1);
496 ret
= si2165_writereg8(state
, 0x0344, patch_version
);
501 ret
= si2165_writereg8(state
, 0x0379, 0x01);
505 ret
= si2165_upload_firmware_block(state
, data
, len
,
506 &offset
, block_count
);
508 dev_err(&state
->client
->dev
,
509 "%s: firmware could not be uploaded\n",
515 ret
= si2165_readreg16(state
, 0x037a, &val16
);
519 if (val16
!= crc_expected
) {
520 dev_err(&state
->client
->dev
,
521 "%s: firmware crc mismatch %04x != %04x\n",
522 KBUILD_MODNAME
, val16
, crc_expected
);
527 ret
= si2165_upload_firmware_block(state
, data
, len
, &offset
, 5);
532 dev_err(&state
->client
->dev
,
533 "%s: firmware len mismatch %04x != %04x\n",
534 KBUILD_MODNAME
, len
, offset
);
539 /* reset watchdog error register */
540 ret
= si2165_writereg_mask8(state
, 0x0341, 0x02, 0x02);
544 /* enable reset on error */
545 ret
= si2165_writereg_mask8(state
, 0x035c, 0x01, 0x01);
549 dev_info(&state
->client
->dev
, "%s: fw load finished\n", KBUILD_MODNAME
);
552 state
->firmware_loaded
= true;
555 release_firmware(fw
);
562 static int si2165_init(struct dvb_frontend
*fe
)
565 struct si2165_state
*state
= fe
->demodulator_priv
;
567 u8 patch_version
= 0x00;
569 dprintk("%s: called\n", __func__
);
572 ret
= si2165_writereg8(state
, 0x0000, state
->config
.chip_mode
);
575 /* dsp_clock_enable */
576 ret
= si2165_writereg8(state
, 0x0104, 0x01);
579 ret
= si2165_readreg8(state
, 0x0000, &val
); /* verify chip_mode */
582 if (val
!= state
->config
.chip_mode
) {
583 dev_err(&state
->client
->dev
, "%s: could not set chip_mode\n",
589 ret
= si2165_writereg8(state
, 0x018b, 0x00);
592 ret
= si2165_writereg8(state
, 0x0190, 0x01);
595 ret
= si2165_writereg8(state
, 0x0170, 0x00);
598 ret
= si2165_writereg8(state
, 0x0171, 0x07);
602 ret
= si2165_writereg8(state
, 0x0646, 0x00);
605 ret
= si2165_writereg8(state
, 0x0641, 0x00);
609 ret
= si2165_init_pll(state
);
613 /* enable chip_init */
614 ret
= si2165_writereg8(state
, 0x0050, 0x01);
618 ret
= si2165_writereg8(state
, 0x0096, 0x01);
621 ret
= si2165_wait_init_done(state
);
625 /* disable chip_init */
626 ret
= si2165_writereg8(state
, 0x0050, 0x00);
631 ret
= si2165_writereg16(state
, 0x0470, 0x7530);
635 ret
= si2165_readreg8(state
, 0x0344, &patch_version
);
639 ret
= si2165_writereg8(state
, 0x00cb, 0x00);
644 ret
= si2165_writereg32(state
, 0x0348, 0xf4000000);
647 /* boot/wdog status */
648 ret
= si2165_readreg8(state
, 0x0341, &val
);
652 if (patch_version
== 0x00) {
653 ret
= si2165_upload_firmware(state
);
658 /* ts output config */
659 ret
= si2165_writereg8(state
, 0x04e4, 0x20);
662 ret
= si2165_writereg16(state
, 0x04ef, 0x00fe);
665 ret
= si2165_writereg24(state
, 0x04f4, 0x555555);
668 ret
= si2165_writereg8(state
, 0x04e5, 0x01);
677 static int si2165_sleep(struct dvb_frontend
*fe
)
680 struct si2165_state
*state
= fe
->demodulator_priv
;
682 /* dsp clock disable */
683 ret
= si2165_writereg8(state
, 0x0104, 0x00);
687 ret
= si2165_writereg8(state
, 0x0000, SI2165_MODE_OFF
);
693 static int si2165_read_status(struct dvb_frontend
*fe
, enum fe_status
*status
)
697 struct si2165_state
*state
= fe
->demodulator_priv
;
699 if (!state
->has_dvbt
)
703 ret
= si2165_readreg8(state
, 0x4e0, &fec_lock
);
707 if (fec_lock
& 0x01) {
708 *status
|= FE_HAS_SIGNAL
;
709 *status
|= FE_HAS_CARRIER
;
710 *status
|= FE_HAS_VITERBI
;
711 *status
|= FE_HAS_SYNC
;
712 *status
|= FE_HAS_LOCK
;
718 static int si2165_set_oversamp(struct si2165_state
*state
, u32 dvb_rate
)
726 oversamp
= si2165_get_fe_clk(state
);
728 do_div(oversamp
, dvb_rate
);
729 reg_value
= oversamp
& 0x3fffffff;
731 dprintk("%s: Write oversamp=%#x\n", __func__
, reg_value
);
732 return si2165_writereg32(state
, 0x00e4, reg_value
);
735 static int si2165_set_if_freq_shift(struct si2165_state
*state
)
737 struct dvb_frontend
*fe
= &state
->fe
;
740 u32 fe_clk
= si2165_get_fe_clk(state
);
743 if (!fe
->ops
.tuner_ops
.get_if_frequency
) {
744 dev_err(&state
->client
->dev
,
745 "%s: Error: get_if_frequency() not defined at tuner. Can't work without it!\n",
753 fe
->ops
.tuner_ops
.get_if_frequency(fe
, &IF
);
755 if_freq_shift
<<= 29;
757 do_div(if_freq_shift
, fe_clk
);
758 reg_value
= (s32
)if_freq_shift
;
760 if (state
->config
.inversion
)
761 reg_value
= -reg_value
;
763 reg_value
= reg_value
& 0x1fffffff;
765 /* if_freq_shift, usbdump contained 0x023ee08f; */
766 return si2165_writereg32(state
, 0x00e8, reg_value
);
769 static const struct si2165_reg_value_pair dvbt_regs
[] = {
770 /* standard = DVB-T */
773 /* impulsive_noise_remover */
786 /* freq_sync_range */
787 REG16(0x030c, 0x0064),
792 static int si2165_set_frontend_dvbt(struct dvb_frontend
*fe
)
795 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
796 struct si2165_state
*state
= fe
->demodulator_priv
;
799 u32 bw_hz
= p
->bandwidth_hz
;
801 dprintk("%s: called\n", __func__
);
803 if (!state
->has_dvbt
)
806 /* no bandwidth auto-detection */
810 dvb_rate
= bw_hz
* 8 / 7;
811 bw10k
= bw_hz
/ 10000;
813 ret
= si2165_adjust_pll_divl(state
, 12);
817 /* bandwidth in 10KHz steps */
818 ret
= si2165_writereg16(state
, 0x0308, bw10k
);
821 ret
= si2165_set_oversamp(state
, dvb_rate
);
825 ret
= si2165_write_reg_list(state
, dvbt_regs
, ARRAY_SIZE(dvbt_regs
));
832 static const struct si2165_reg_value_pair dvbc_regs
[] = {
833 /* standard = DVB-C */
852 REG16(0x0350, 0x3e80),
856 REG16(0x024c, 0x0000),
857 REG16(0x027c, 0x0000),
863 static int si2165_set_frontend_dvbc(struct dvb_frontend
*fe
)
865 struct si2165_state
*state
= fe
->demodulator_priv
;
867 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
868 const u32 dvb_rate
= p
->symbol_rate
;
869 const u32 bw_hz
= p
->bandwidth_hz
;
871 if (!state
->has_dvbc
)
877 ret
= si2165_adjust_pll_divl(state
, 14);
882 ret
= si2165_set_oversamp(state
, dvb_rate
);
886 ret
= si2165_writereg32(state
, 0x00c4, bw_hz
);
890 ret
= si2165_write_reg_list(state
, dvbc_regs
, ARRAY_SIZE(dvbc_regs
));
897 static const struct si2165_reg_value_pair agc_rewrite
[] = {
905 static int si2165_set_frontend(struct dvb_frontend
*fe
)
907 struct si2165_state
*state
= fe
->demodulator_priv
;
908 struct dtv_frontend_properties
*p
= &fe
->dtv_property_cache
;
909 u32 delsys
= p
->delivery_system
;
913 /* initial setting of if freq shift */
914 ret
= si2165_set_if_freq_shift(state
);
920 ret
= si2165_set_frontend_dvbt(fe
);
924 case SYS_DVBC_ANNEX_A
:
925 ret
= si2165_set_frontend_dvbc(fe
);
934 ret
= si2165_writereg32(state
, 0x0348, 0xf4000000);
938 if (fe
->ops
.tuner_ops
.set_params
)
939 fe
->ops
.tuner_ops
.set_params(fe
);
941 /* recalc if_freq_shift if IF might has changed */
942 ret
= si2165_set_if_freq_shift(state
);
946 /* boot/wdog status */
947 ret
= si2165_readreg8(state
, 0x0341, val
);
950 ret
= si2165_writereg8(state
, 0x0341, 0x00);
955 ret
= si2165_writereg8(state
, 0x00c0, 0x00);
959 ret
= si2165_writereg32(state
, 0x0384, 0x00000000);
963 /* write adc values after each reset*/
964 ret
= si2165_write_reg_list(state
, agc_rewrite
,
965 ARRAY_SIZE(agc_rewrite
));
970 ret
= si2165_writereg8(state
, 0x02e0, 0x01);
973 /* boot/wdog status */
974 ret
= si2165_readreg8(state
, 0x0341, val
);
981 static const struct dvb_frontend_ops si2165_ops
= {
983 .name
= "Silicon Labs ",
985 .symbol_rate_min
= 1000000,
986 .symbol_rate_max
= 7200000,
988 .frequency_stepsize
= 166667,
989 .caps
= FE_CAN_FEC_1_2
|
1002 FE_CAN_GUARD_INTERVAL_AUTO
|
1003 FE_CAN_HIERARCHY_AUTO
|
1005 FE_CAN_TRANSMISSION_MODE_AUTO
|
1009 .get_tune_settings
= si2165_get_tune_settings
,
1011 .init
= si2165_init
,
1012 .sleep
= si2165_sleep
,
1014 .set_frontend
= si2165_set_frontend
,
1015 .read_status
= si2165_read_status
,
1018 static int si2165_probe(struct i2c_client
*client
,
1019 const struct i2c_device_id
*id
)
1021 struct si2165_state
*state
= NULL
;
1022 struct si2165_platform_data
*pdata
= client
->dev
.platform_data
;
1027 const char *chip_name
;
1028 static const struct regmap_config regmap_config
= {
1031 .max_register
= 0x08ff,
1034 /* allocate memory for the internal state */
1035 state
= kzalloc(sizeof(struct si2165_state
), GFP_KERNEL
);
1036 if (state
== NULL
) {
1042 state
->regmap
= devm_regmap_init_i2c(client
, ®map_config
);
1043 if (IS_ERR(state
->regmap
)) {
1044 ret
= PTR_ERR(state
->regmap
);
1048 /* setup the state */
1049 state
->client
= client
;
1050 state
->config
.i2c_addr
= client
->addr
;
1051 state
->config
.chip_mode
= pdata
->chip_mode
;
1052 state
->config
.ref_freq_Hz
= pdata
->ref_freq_Hz
;
1053 state
->config
.inversion
= pdata
->inversion
;
1055 if (state
->config
.ref_freq_Hz
< 4000000
1056 || state
->config
.ref_freq_Hz
> 27000000) {
1057 dev_err(&state
->client
->dev
, "%s: ref_freq of %d Hz not supported by this driver\n",
1058 KBUILD_MODNAME
, state
->config
.ref_freq_Hz
);
1063 /* create dvb_frontend */
1064 memcpy(&state
->fe
.ops
, &si2165_ops
,
1065 sizeof(struct dvb_frontend_ops
));
1066 state
->fe
.ops
.release
= NULL
;
1067 state
->fe
.demodulator_priv
= state
;
1068 i2c_set_clientdata(client
, state
);
1071 ret
= si2165_writereg8(state
, 0x0000, state
->config
.chip_mode
);
1075 ret
= si2165_readreg8(state
, 0x0000, &val
);
1078 if (val
!= state
->config
.chip_mode
)
1081 ret
= si2165_readreg8(state
, 0x0023, &state
->chip_revcode
);
1085 ret
= si2165_readreg8(state
, 0x0118, &state
->chip_type
);
1090 ret
= si2165_writereg8(state
, 0x0000, SI2165_MODE_OFF
);
1094 if (state
->chip_revcode
< 26)
1095 rev_char
= 'A' + state
->chip_revcode
;
1099 switch (state
->chip_type
) {
1101 chip_name
= "Si2161";
1102 state
->has_dvbt
= true;
1105 chip_name
= "Si2165";
1106 state
->has_dvbt
= true;
1107 state
->has_dvbc
= true;
1110 dev_err(&state
->client
->dev
, "%s: Unsupported Silicon Labs chip (type %d, rev %d)\n",
1111 KBUILD_MODNAME
, state
->chip_type
, state
->chip_revcode
);
1115 dev_info(&state
->client
->dev
,
1116 "%s: Detected Silicon Labs %s-%c (type %d, rev %d)\n",
1117 KBUILD_MODNAME
, chip_name
, rev_char
, state
->chip_type
,
1118 state
->chip_revcode
);
1120 strlcat(state
->fe
.ops
.info
.name
, chip_name
,
1121 sizeof(state
->fe
.ops
.info
.name
));
1124 if (state
->has_dvbt
) {
1125 state
->fe
.ops
.delsys
[n
++] = SYS_DVBT
;
1126 strlcat(state
->fe
.ops
.info
.name
, " DVB-T",
1127 sizeof(state
->fe
.ops
.info
.name
));
1129 if (state
->has_dvbc
) {
1130 state
->fe
.ops
.delsys
[n
++] = SYS_DVBC_ANNEX_A
;
1131 strlcat(state
->fe
.ops
.info
.name
, " DVB-C",
1132 sizeof(state
->fe
.ops
.info
.name
));
1135 /* return fe pointer */
1136 *pdata
->fe
= &state
->fe
;
1144 dev_dbg(&client
->dev
, "failed=%d\n", ret
);
1148 static int si2165_remove(struct i2c_client
*client
)
1150 struct si2165_state
*state
= i2c_get_clientdata(client
);
1152 dev_dbg(&client
->dev
, "\n");
1158 static const struct i2c_device_id si2165_id_table
[] = {
1162 MODULE_DEVICE_TABLE(i2c
, si2165_id_table
);
1164 static struct i2c_driver si2165_driver
= {
1166 .owner
= THIS_MODULE
,
1169 .probe
= si2165_probe
,
1170 .remove
= si2165_remove
,
1171 .id_table
= si2165_id_table
,
1174 module_i2c_driver(si2165_driver
);
1176 module_param(debug
, int, 0644);
1177 MODULE_PARM_DESC(debug
, "Turn on/off frontend debugging (default:off).");
1179 MODULE_DESCRIPTION("Silicon Labs Si2165 DVB-C/-T Demodulator driver");
1180 MODULE_AUTHOR("Matthias Schwarzott <zzam@gentoo.org>");
1181 MODULE_LICENSE("GPL");
1182 MODULE_FIRMWARE(SI2165_FIRMWARE_REV_D
);