1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
23e54a169SMatthias Schwarzott /*
318349f40SMatthias Schwarzott  *  Driver for Silicon Labs Si2161 DVB-T and Si2165 DVB-C/-T Demodulator
418349f40SMatthias Schwarzott  *
577f887cdSMatthias Schwarzott  *  Copyright (C) 2013-2017 Matthias Schwarzott <zzam@gentoo.org>
618349f40SMatthias Schwarzott  *
718349f40SMatthias Schwarzott  *  References:
8965045caSAlexander A. Klimov  *  https://www.silabs.com/Support%20Documents/TechnicalDocs/Si2165-short.pdf
93e54a169SMatthias Schwarzott  */
103e54a169SMatthias Schwarzott 
113e54a169SMatthias Schwarzott #include <linux/delay.h>
123e54a169SMatthias Schwarzott #include <linux/errno.h>
133e54a169SMatthias Schwarzott #include <linux/init.h>
143e54a169SMatthias Schwarzott #include <linux/kernel.h>
153e54a169SMatthias Schwarzott #include <linux/module.h>
163e54a169SMatthias Schwarzott #include <linux/string.h>
173e54a169SMatthias Schwarzott #include <linux/slab.h>
183e54a169SMatthias Schwarzott #include <linux/firmware.h>
19e3ea5e94SMatthias Schwarzott #include <linux/regmap.h>
203e54a169SMatthias Schwarzott 
21fada1935SMauro Carvalho Chehab #include <media/dvb_frontend.h>
22*f97fa3dcSAndy Shevchenko #include <linux/int_log.h>
233e54a169SMatthias Schwarzott #include "si2165_priv.h"
243e54a169SMatthias Schwarzott #include "si2165.h"
253e54a169SMatthias Schwarzott 
2618349f40SMatthias Schwarzott /*
2718349f40SMatthias Schwarzott  * Hauppauge WinTV-HVR-930C-HD B130 / PCTV QuatroStick 521e 1113xx
2818349f40SMatthias Schwarzott  * uses 16 MHz xtal
2918349f40SMatthias Schwarzott  *
3018349f40SMatthias Schwarzott  * Hauppauge WinTV-HVR-930C-HD B131 / PCTV QuatroStick 522e 1114xx
3118349f40SMatthias Schwarzott  * uses 24 MHz clock provided by tuner
3218349f40SMatthias Schwarzott  */
333e54a169SMatthias Schwarzott 
343e54a169SMatthias Schwarzott struct si2165_state {
357cd785adSMatthias Schwarzott 	struct i2c_client *client;
367cd785adSMatthias Schwarzott 
37e3ea5e94SMatthias Schwarzott 	struct regmap *regmap;
383e54a169SMatthias Schwarzott 
39d9a201dfSMatthias Schwarzott 	struct dvb_frontend fe;
403e54a169SMatthias Schwarzott 
413e54a169SMatthias Schwarzott 	struct si2165_config config;
423e54a169SMatthias Schwarzott 
4355bea400SMatthias Schwarzott 	u8 chip_revcode;
443e54a169SMatthias Schwarzott 	u8 chip_type;
453e54a169SMatthias Schwarzott 
463e54a169SMatthias Schwarzott 	/* calculated by xtal and div settings */
473e54a169SMatthias Schwarzott 	u32 fvco_hz;
483e54a169SMatthias Schwarzott 	u32 sys_clk;
493e54a169SMatthias Schwarzott 	u32 adc_clk;
503e54a169SMatthias Schwarzott 
51e9c7d19aSMatthias Schwarzott 	/* DVBv3 stats */
52e9c7d19aSMatthias Schwarzott 	u64 ber_prev;
53e9c7d19aSMatthias Schwarzott 
543e54a169SMatthias Schwarzott 	bool has_dvbc;
553e54a169SMatthias Schwarzott 	bool has_dvbt;
563e54a169SMatthias Schwarzott 	bool firmware_loaded;
573e54a169SMatthias Schwarzott };
583e54a169SMatthias Schwarzott 
si2165_write(struct si2165_state * state,const u16 reg,const u8 * src,const int count)593e54a169SMatthias Schwarzott static int si2165_write(struct si2165_state *state, const u16 reg,
603e54a169SMatthias Schwarzott 			const u8 *src, const int count)
613e54a169SMatthias Schwarzott {
623e54a169SMatthias Schwarzott 	int ret;
633e54a169SMatthias Schwarzott 
647dbbb4bfSMatthias Schwarzott 	dev_dbg(&state->client->dev, "i2c write: reg: 0x%04x, data: %*ph\n",
657dbbb4bfSMatthias Schwarzott 		reg, count, src);
663e54a169SMatthias Schwarzott 
67e3ea5e94SMatthias Schwarzott 	ret = regmap_bulk_write(state->regmap, reg, src, count);
683e54a169SMatthias Schwarzott 
69e3ea5e94SMatthias Schwarzott 	if (ret)
70aa155449SMatthias Schwarzott 		dev_err(&state->client->dev, "%s: ret == %d\n", __func__, ret);
713e54a169SMatthias Schwarzott 
72e3ea5e94SMatthias Schwarzott 	return ret;
733e54a169SMatthias Schwarzott }
743e54a169SMatthias Schwarzott 
si2165_read(struct si2165_state * state,const u16 reg,u8 * val,const int count)753e54a169SMatthias Schwarzott static int si2165_read(struct si2165_state *state,
763e54a169SMatthias Schwarzott 		       const u16 reg, u8 *val, const int count)
773e54a169SMatthias Schwarzott {
78e3ea5e94SMatthias Schwarzott 	int ret = regmap_bulk_read(state->regmap, reg, val, count);
793e54a169SMatthias Schwarzott 
80e3ea5e94SMatthias Schwarzott 	if (ret) {
81aa155449SMatthias Schwarzott 		dev_err(&state->client->dev, "%s: error (addr %02x reg %04x error (ret == %i)\n",
823e54a169SMatthias Schwarzott 			__func__, state->config.i2c_addr, reg, ret);
833e54a169SMatthias Schwarzott 		return ret;
843e54a169SMatthias Schwarzott 	}
853e54a169SMatthias Schwarzott 
867dbbb4bfSMatthias Schwarzott 	dev_dbg(&state->client->dev, "i2c read: reg: 0x%04x, data: %*ph\n",
877dbbb4bfSMatthias Schwarzott 		reg, count, val);
883e54a169SMatthias Schwarzott 
893e54a169SMatthias Schwarzott 	return 0;
903e54a169SMatthias Schwarzott }
913e54a169SMatthias Schwarzott 
si2165_readreg8(struct si2165_state * state,const u16 reg,u8 * val)923e54a169SMatthias Schwarzott static int si2165_readreg8(struct si2165_state *state,
933e54a169SMatthias Schwarzott 			   const u16 reg, u8 *val)
943e54a169SMatthias Schwarzott {
95e3ea5e94SMatthias Schwarzott 	unsigned int val_tmp;
96e3ea5e94SMatthias Schwarzott 	int ret = regmap_read(state->regmap, reg, &val_tmp);
97e3ea5e94SMatthias Schwarzott 	*val = (u8)val_tmp;
981b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev, "reg read: R(0x%04x)=0x%02x\n", reg, *val);
993e54a169SMatthias Schwarzott 	return ret;
1003e54a169SMatthias Schwarzott }
1013e54a169SMatthias Schwarzott 
si2165_readreg16(struct si2165_state * state,const u16 reg,u16 * val)1023e54a169SMatthias Schwarzott static int si2165_readreg16(struct si2165_state *state,
1033e54a169SMatthias Schwarzott 			    const u16 reg, u16 *val)
1043e54a169SMatthias Schwarzott {
1053e54a169SMatthias Schwarzott 	u8 buf[2];
1063e54a169SMatthias Schwarzott 
1073e54a169SMatthias Schwarzott 	int ret = si2165_read(state, reg, buf, 2);
1083e54a169SMatthias Schwarzott 	*val = buf[0] | buf[1] << 8;
1091b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev, "reg read: R(0x%04x)=0x%04x\n", reg, *val);
1103e54a169SMatthias Schwarzott 	return ret;
1113e54a169SMatthias Schwarzott }
1123e54a169SMatthias Schwarzott 
si2165_readreg24(struct si2165_state * state,const u16 reg,u32 * val)113c0675d0bSMatthias Schwarzott static int si2165_readreg24(struct si2165_state *state,
114c0675d0bSMatthias Schwarzott 			    const u16 reg, u32 *val)
115c0675d0bSMatthias Schwarzott {
116c0675d0bSMatthias Schwarzott 	u8 buf[3];
117c0675d0bSMatthias Schwarzott 
118c0675d0bSMatthias Schwarzott 	int ret = si2165_read(state, reg, buf, 3);
119c0675d0bSMatthias Schwarzott 	*val = buf[0] | buf[1] << 8 | buf[2] << 16;
120c0675d0bSMatthias Schwarzott 	dev_dbg(&state->client->dev, "reg read: R(0x%04x)=0x%06x\n", reg, *val);
121c0675d0bSMatthias Schwarzott 	return ret;
122c0675d0bSMatthias Schwarzott }
123c0675d0bSMatthias Schwarzott 
si2165_writereg8(struct si2165_state * state,const u16 reg,u8 val)1243e54a169SMatthias Schwarzott static int si2165_writereg8(struct si2165_state *state, const u16 reg, u8 val)
1253e54a169SMatthias Schwarzott {
126e3ea5e94SMatthias Schwarzott 	return regmap_write(state->regmap, reg, val);
1273e54a169SMatthias Schwarzott }
1283e54a169SMatthias Schwarzott 
si2165_writereg16(struct si2165_state * state,const u16 reg,u16 val)1293e54a169SMatthias Schwarzott static int si2165_writereg16(struct si2165_state *state, const u16 reg, u16 val)
1303e54a169SMatthias Schwarzott {
1313e54a169SMatthias Schwarzott 	u8 buf[2] = { val & 0xff, (val >> 8) & 0xff };
1323e54a169SMatthias Schwarzott 
1333e54a169SMatthias Schwarzott 	return si2165_write(state, reg, buf, 2);
1343e54a169SMatthias Schwarzott }
1353e54a169SMatthias Schwarzott 
si2165_writereg24(struct si2165_state * state,const u16 reg,u32 val)1363e54a169SMatthias Schwarzott static int si2165_writereg24(struct si2165_state *state, const u16 reg, u32 val)
1373e54a169SMatthias Schwarzott {
1383e54a169SMatthias Schwarzott 	u8 buf[3] = { val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff };
1393e54a169SMatthias Schwarzott 
1403e54a169SMatthias Schwarzott 	return si2165_write(state, reg, buf, 3);
1413e54a169SMatthias Schwarzott }
1423e54a169SMatthias Schwarzott 
si2165_writereg32(struct si2165_state * state,const u16 reg,u32 val)1433e54a169SMatthias Schwarzott static int si2165_writereg32(struct si2165_state *state, const u16 reg, u32 val)
1443e54a169SMatthias Schwarzott {
1453e54a169SMatthias Schwarzott 	u8 buf[4] = {
1463e54a169SMatthias Schwarzott 		val & 0xff,
1473e54a169SMatthias Schwarzott 		(val >> 8) & 0xff,
1483e54a169SMatthias Schwarzott 		(val >> 16) & 0xff,
1493e54a169SMatthias Schwarzott 		(val >> 24) & 0xff
1503e54a169SMatthias Schwarzott 	};
1513e54a169SMatthias Schwarzott 	return si2165_write(state, reg, buf, 4);
1523e54a169SMatthias Schwarzott }
1533e54a169SMatthias Schwarzott 
si2165_writereg_mask8(struct si2165_state * state,const u16 reg,u8 val,u8 mask)1543e54a169SMatthias Schwarzott static int si2165_writereg_mask8(struct si2165_state *state, const u16 reg,
1553e54a169SMatthias Schwarzott 				 u8 val, u8 mask)
1563e54a169SMatthias Schwarzott {
1573e54a169SMatthias Schwarzott 	if (mask != 0xff) {
158c2e5c951SMarkus Elfring 		u8 tmp;
159c2e5c951SMarkus Elfring 		int ret = si2165_readreg8(state, reg, &tmp);
160c2e5c951SMarkus Elfring 
1613e54a169SMatthias Schwarzott 		if (ret < 0)
162c2e5c951SMarkus Elfring 			return ret;
1633e54a169SMatthias Schwarzott 
1643e54a169SMatthias Schwarzott 		val &= mask;
1653e54a169SMatthias Schwarzott 		tmp &= ~mask;
1663e54a169SMatthias Schwarzott 		val |= tmp;
1673e54a169SMatthias Schwarzott 	}
168c2e5c951SMarkus Elfring 	return si2165_writereg8(state, reg, val);
1693e54a169SMatthias Schwarzott }
1703e54a169SMatthias Schwarzott 
1717dbbb4bfSMatthias Schwarzott #define REG16(reg, val) \
1727dbbb4bfSMatthias Schwarzott 	{ (reg), (val) & 0xff }, \
1737dbbb4bfSMatthias Schwarzott 	{ (reg) + 1, (val) >> 8 & 0xff }
174a5293dbdSMatthias Schwarzott struct si2165_reg_value_pair {
175a5293dbdSMatthias Schwarzott 	u16 reg;
176a5293dbdSMatthias Schwarzott 	u8 val;
177a5293dbdSMatthias Schwarzott };
178a5293dbdSMatthias Schwarzott 
si2165_write_reg_list(struct si2165_state * state,const struct si2165_reg_value_pair * regs,int count)179a5293dbdSMatthias Schwarzott static int si2165_write_reg_list(struct si2165_state *state,
180a5293dbdSMatthias Schwarzott 				 const struct si2165_reg_value_pair *regs,
181a5293dbdSMatthias Schwarzott 				 int count)
182a5293dbdSMatthias Schwarzott {
183a5293dbdSMatthias Schwarzott 	int i;
184a5293dbdSMatthias Schwarzott 	int ret;
185a5293dbdSMatthias Schwarzott 
186a5293dbdSMatthias Schwarzott 	for (i = 0; i < count; i++) {
187a5293dbdSMatthias Schwarzott 		ret = si2165_writereg8(state, regs[i].reg, regs[i].val);
188a5293dbdSMatthias Schwarzott 		if (ret < 0)
189a5293dbdSMatthias Schwarzott 			return ret;
190a5293dbdSMatthias Schwarzott 	}
191a5293dbdSMatthias Schwarzott 	return 0;
192a5293dbdSMatthias Schwarzott }
193a5293dbdSMatthias Schwarzott 
si2165_get_tune_settings(struct dvb_frontend * fe,struct dvb_frontend_tune_settings * s)1943e54a169SMatthias Schwarzott static int si2165_get_tune_settings(struct dvb_frontend *fe,
1953e54a169SMatthias Schwarzott 				    struct dvb_frontend_tune_settings *s)
1963e54a169SMatthias Schwarzott {
1973e54a169SMatthias Schwarzott 	s->min_delay_ms = 1000;
1983e54a169SMatthias Schwarzott 	return 0;
1993e54a169SMatthias Schwarzott }
2003e54a169SMatthias Schwarzott 
si2165_init_pll(struct si2165_state * state)2013e54a169SMatthias Schwarzott static int si2165_init_pll(struct si2165_state *state)
2023e54a169SMatthias Schwarzott {
2037dbbb4bfSMatthias Schwarzott 	u32 ref_freq_hz = state->config.ref_freq_hz;
2043e54a169SMatthias Schwarzott 	u8 divr = 1; /* 1..7 */
2053e54a169SMatthias Schwarzott 	u8 divp = 1; /* only 1 or 4 */
2063e54a169SMatthias Schwarzott 	u8 divn = 56; /* 1..63 */
2073e54a169SMatthias Schwarzott 	u8 divm = 8;
2083e54a169SMatthias Schwarzott 	u8 divl = 12;
2093e54a169SMatthias Schwarzott 	u8 buf[4];
2103e54a169SMatthias Schwarzott 
21118349f40SMatthias Schwarzott 	/*
21218349f40SMatthias Schwarzott 	 * hardcoded values can be deleted if calculation is verified
21318349f40SMatthias Schwarzott 	 * or it yields the same values as the windows driver
21418349f40SMatthias Schwarzott 	 */
2157dbbb4bfSMatthias Schwarzott 	switch (ref_freq_hz) {
2163e54a169SMatthias Schwarzott 	case 16000000u:
2173e54a169SMatthias Schwarzott 		divn = 56;
2183e54a169SMatthias Schwarzott 		break;
2193e54a169SMatthias Schwarzott 	case 24000000u:
2203e54a169SMatthias Schwarzott 		divr = 2;
2213e54a169SMatthias Schwarzott 		divp = 4;
2223e54a169SMatthias Schwarzott 		divn = 19;
2233e54a169SMatthias Schwarzott 		break;
2243e54a169SMatthias Schwarzott 	default:
2253e54a169SMatthias Schwarzott 		/* ref_freq / divr must be between 4 and 16 MHz */
2267dbbb4bfSMatthias Schwarzott 		if (ref_freq_hz > 16000000u)
2273e54a169SMatthias Schwarzott 			divr = 2;
2283e54a169SMatthias Schwarzott 
22918349f40SMatthias Schwarzott 		/*
23018349f40SMatthias Schwarzott 		 * now select divn and divp such that
23118349f40SMatthias Schwarzott 		 * fvco is in 1624..1824 MHz
23218349f40SMatthias Schwarzott 		 */
2337dbbb4bfSMatthias Schwarzott 		if (1624000000u * divr > ref_freq_hz * 2u * 63u)
2343e54a169SMatthias Schwarzott 			divp = 4;
2353e54a169SMatthias Schwarzott 
2363e54a169SMatthias Schwarzott 		/* is this already correct regarding rounding? */
2377dbbb4bfSMatthias Schwarzott 		divn = 1624000000u * divr / (ref_freq_hz * 2u * divp);
2383e54a169SMatthias Schwarzott 		break;
2393e54a169SMatthias Schwarzott 	}
2403e54a169SMatthias Schwarzott 
2413e54a169SMatthias Schwarzott 	/* adc_clk and sys_clk depend on xtal and pll settings */
2427dbbb4bfSMatthias Schwarzott 	state->fvco_hz = ref_freq_hz / divr
2433e54a169SMatthias Schwarzott 			* 2u * divn * divp;
2443e54a169SMatthias Schwarzott 	state->adc_clk = state->fvco_hz / (divm * 4u);
2453e54a169SMatthias Schwarzott 	state->sys_clk = state->fvco_hz / (divl * 2u);
2463e54a169SMatthias Schwarzott 
247814f86c9SMatthias Schwarzott 	/* write all 4 pll registers 0x00a0..0x00a3 at once */
2483e54a169SMatthias Schwarzott 	buf[0] = divl;
2493e54a169SMatthias Schwarzott 	buf[1] = divm;
2503e54a169SMatthias Schwarzott 	buf[2] = (divn & 0x3f) | ((divp == 1) ? 0x40 : 0x00) | 0x80;
2513e54a169SMatthias Schwarzott 	buf[3] = divr;
252814f86c9SMatthias Schwarzott 	return si2165_write(state, REG_PLL_DIVL, buf, 4);
2533e54a169SMatthias Schwarzott }
2543e54a169SMatthias Schwarzott 
si2165_adjust_pll_divl(struct si2165_state * state,u8 divl)2553e54a169SMatthias Schwarzott static int si2165_adjust_pll_divl(struct si2165_state *state, u8 divl)
2563e54a169SMatthias Schwarzott {
2573e54a169SMatthias Schwarzott 	state->sys_clk = state->fvco_hz / (divl * 2u);
258814f86c9SMatthias Schwarzott 	return si2165_writereg8(state, REG_PLL_DIVL, divl);
2593e54a169SMatthias Schwarzott }
2603e54a169SMatthias Schwarzott 
si2165_get_fe_clk(struct si2165_state * state)2613e54a169SMatthias Schwarzott static u32 si2165_get_fe_clk(struct si2165_state *state)
2623e54a169SMatthias Schwarzott {
2633e54a169SMatthias Schwarzott 	/* assume Oversampling mode Ovr4 is used */
2643e54a169SMatthias Schwarzott 	return state->adc_clk;
2653e54a169SMatthias Schwarzott }
2663e54a169SMatthias Schwarzott 
si2165_wait_init_done(struct si2165_state * state)267e73c7bfeSHans Verkuil static int si2165_wait_init_done(struct si2165_state *state)
2683e54a169SMatthias Schwarzott {
2690ab34a08SKangjie Lu 	int ret;
2703e54a169SMatthias Schwarzott 	u8 val = 0;
2713e54a169SMatthias Schwarzott 	int i;
2723e54a169SMatthias Schwarzott 
2733e54a169SMatthias Schwarzott 	for (i = 0; i < 3; ++i) {
2740ab34a08SKangjie Lu 		ret = si2165_readreg8(state, REG_INIT_DONE, &val);
2750ab34a08SKangjie Lu 		if (ret < 0)
2760ab34a08SKangjie Lu 			return ret;
2773e54a169SMatthias Schwarzott 		if (val == 0x01)
2783e54a169SMatthias Schwarzott 			return 0;
2793e54a169SMatthias Schwarzott 		usleep_range(1000, 50000);
2803e54a169SMatthias Schwarzott 	}
28177f887cdSMatthias Schwarzott 	dev_err(&state->client->dev, "init_done was not set\n");
2820ab34a08SKangjie Lu 	return -EINVAL;
2833e54a169SMatthias Schwarzott }
2843e54a169SMatthias Schwarzott 
si2165_upload_firmware_block(struct si2165_state * state,const u8 * data,u32 len,u32 * poffset,u32 block_count)2853e54a169SMatthias Schwarzott static int si2165_upload_firmware_block(struct si2165_state *state,
2867dbbb4bfSMatthias Schwarzott 					const u8 *data, u32 len, u32 *poffset,
2877dbbb4bfSMatthias Schwarzott 					u32 block_count)
2883e54a169SMatthias Schwarzott {
2893e54a169SMatthias Schwarzott 	int ret;
2903e54a169SMatthias Schwarzott 	u8 buf_ctrl[4] = { 0x00, 0x00, 0x00, 0xc0 };
2913e54a169SMatthias Schwarzott 	u8 wordcount;
2923e54a169SMatthias Schwarzott 	u32 cur_block = 0;
2933e54a169SMatthias Schwarzott 	u32 offset = poffset ? *poffset : 0;
2943e54a169SMatthias Schwarzott 
2953e54a169SMatthias Schwarzott 	if (len < 4)
2963e54a169SMatthias Schwarzott 		return -EINVAL;
2973e54a169SMatthias Schwarzott 	if (len % 4 != 0)
2983e54a169SMatthias Schwarzott 		return -EINVAL;
2993e54a169SMatthias Schwarzott 
3001b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev,
3017dbbb4bfSMatthias Schwarzott 		"fw load: %s: called with len=0x%x offset=0x%x blockcount=0x%x\n",
3027dbbb4bfSMatthias Schwarzott 		__func__, len, offset, block_count);
3033e54a169SMatthias Schwarzott 	while (offset + 12 <= len && cur_block < block_count) {
3041b54da77SMatthias Schwarzott 		dev_dbg(&state->client->dev,
3057dbbb4bfSMatthias Schwarzott 			"fw load: %s: in while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
3067dbbb4bfSMatthias Schwarzott 			__func__, len, offset, cur_block, block_count);
3073e54a169SMatthias Schwarzott 		wordcount = data[offset];
3083e54a169SMatthias Schwarzott 		if (wordcount < 1 || data[offset + 1] ||
3093e54a169SMatthias Schwarzott 		    data[offset + 2] || data[offset + 3]) {
310aa155449SMatthias Schwarzott 			dev_warn(&state->client->dev,
31177f887cdSMatthias Schwarzott 				 "bad fw data[0..3] = %*ph\n",
31277f887cdSMatthias Schwarzott 				 4, data);
3133e54a169SMatthias Schwarzott 			return -EINVAL;
3143e54a169SMatthias Schwarzott 		}
3153e54a169SMatthias Schwarzott 
3163e54a169SMatthias Schwarzott 		if (offset + 8 + wordcount * 4 > len) {
317aa155449SMatthias Schwarzott 			dev_warn(&state->client->dev,
31877f887cdSMatthias Schwarzott 				 "len is too small for block len=%d, wordcount=%d\n",
31977f887cdSMatthias Schwarzott 				len, wordcount);
3203e54a169SMatthias Schwarzott 			return -EINVAL;
3213e54a169SMatthias Schwarzott 		}
3223e54a169SMatthias Schwarzott 
3233e54a169SMatthias Schwarzott 		buf_ctrl[0] = wordcount - 1;
3243e54a169SMatthias Schwarzott 
325814f86c9SMatthias Schwarzott 		ret = si2165_write(state, REG_DCOM_CONTROL_BYTE, buf_ctrl, 4);
3263e54a169SMatthias Schwarzott 		if (ret < 0)
3273e54a169SMatthias Schwarzott 			goto error;
328814f86c9SMatthias Schwarzott 		ret = si2165_write(state, REG_DCOM_ADDR, data + offset + 4, 4);
3293e54a169SMatthias Schwarzott 		if (ret < 0)
3303e54a169SMatthias Schwarzott 			goto error;
3313e54a169SMatthias Schwarzott 
3323e54a169SMatthias Schwarzott 		offset += 8;
3333e54a169SMatthias Schwarzott 
3343e54a169SMatthias Schwarzott 		while (wordcount > 0) {
335814f86c9SMatthias Schwarzott 			ret = si2165_write(state, REG_DCOM_DATA,
336814f86c9SMatthias Schwarzott 					   data + offset, 4);
3373e54a169SMatthias Schwarzott 			if (ret < 0)
3383e54a169SMatthias Schwarzott 				goto error;
3393e54a169SMatthias Schwarzott 			wordcount--;
3403e54a169SMatthias Schwarzott 			offset += 4;
3413e54a169SMatthias Schwarzott 		}
3423e54a169SMatthias Schwarzott 		cur_block++;
3433e54a169SMatthias Schwarzott 	}
3443e54a169SMatthias Schwarzott 
3451b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev,
3467dbbb4bfSMatthias Schwarzott 		"fw load: %s: after while len=0x%x offset=0x%x cur_block=0x%x blockcount=0x%x\n",
3477dbbb4bfSMatthias Schwarzott 		__func__, len, offset, cur_block, block_count);
3483e54a169SMatthias Schwarzott 
3493e54a169SMatthias Schwarzott 	if (poffset)
3503e54a169SMatthias Schwarzott 		*poffset = offset;
3513e54a169SMatthias Schwarzott 
3521b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev,
3537dbbb4bfSMatthias Schwarzott 		"fw load: %s: returned offset=0x%x\n",
3547dbbb4bfSMatthias Schwarzott 		__func__, offset);
3553e54a169SMatthias Schwarzott 
3563e54a169SMatthias Schwarzott 	return 0;
3573e54a169SMatthias Schwarzott error:
3583e54a169SMatthias Schwarzott 	return ret;
3593e54a169SMatthias Schwarzott }
3603e54a169SMatthias Schwarzott 
si2165_upload_firmware(struct si2165_state * state)3613e54a169SMatthias Schwarzott static int si2165_upload_firmware(struct si2165_state *state)
3623e54a169SMatthias Schwarzott {
3633e54a169SMatthias Schwarzott 	/* int ret; */
3643e54a169SMatthias Schwarzott 	u8 val[3];
3653e54a169SMatthias Schwarzott 	u16 val16;
3663e54a169SMatthias Schwarzott 	int ret;
3673e54a169SMatthias Schwarzott 
3683e54a169SMatthias Schwarzott 	const struct firmware *fw = NULL;
36955bea400SMatthias Schwarzott 	u8 *fw_file;
3703e54a169SMatthias Schwarzott 	const u8 *data;
3713e54a169SMatthias Schwarzott 	u32 len;
3723e54a169SMatthias Schwarzott 	u32 offset;
3733e54a169SMatthias Schwarzott 	u8 patch_version;
3743e54a169SMatthias Schwarzott 	u8 block_count;
3753e54a169SMatthias Schwarzott 	u16 crc_expected;
3763e54a169SMatthias Schwarzott 
37755bea400SMatthias Schwarzott 	switch (state->chip_revcode) {
37855bea400SMatthias Schwarzott 	case 0x03: /* revision D */
37955bea400SMatthias Schwarzott 		fw_file = SI2165_FIRMWARE_REV_D;
38055bea400SMatthias Schwarzott 		break;
38155bea400SMatthias Schwarzott 	default:
38277f887cdSMatthias Schwarzott 		dev_info(&state->client->dev, "no firmware file for revision=%d\n",
38377f887cdSMatthias Schwarzott 			 state->chip_revcode);
38455bea400SMatthias Schwarzott 		return 0;
38555bea400SMatthias Schwarzott 	}
38655bea400SMatthias Schwarzott 
3873e54a169SMatthias Schwarzott 	/* request the firmware, this will block and timeout */
388aa155449SMatthias Schwarzott 	ret = request_firmware(&fw, fw_file, &state->client->dev);
3893e54a169SMatthias Schwarzott 	if (ret) {
39077f887cdSMatthias Schwarzott 		dev_warn(&state->client->dev, "firmware file '%s' not found\n",
39177f887cdSMatthias Schwarzott 			 fw_file);
3923e54a169SMatthias Schwarzott 		goto error;
3933e54a169SMatthias Schwarzott 	}
3943e54a169SMatthias Schwarzott 
3953e54a169SMatthias Schwarzott 	data = fw->data;
3963e54a169SMatthias Schwarzott 	len = fw->size;
3973e54a169SMatthias Schwarzott 
39877f887cdSMatthias Schwarzott 	dev_info(&state->client->dev, "downloading firmware from file '%s' size=%d\n",
39977f887cdSMatthias Schwarzott 		 fw_file, len);
4003e54a169SMatthias Schwarzott 
4013e54a169SMatthias Schwarzott 	if (len % 4 != 0) {
40277f887cdSMatthias Schwarzott 		dev_warn(&state->client->dev, "firmware size is not multiple of 4\n");
4033e54a169SMatthias Schwarzott 		ret = -EINVAL;
4043e54a169SMatthias Schwarzott 		goto error;
4053e54a169SMatthias Schwarzott 	}
4063e54a169SMatthias Schwarzott 
4073e54a169SMatthias Schwarzott 	/* check header (8 bytes) */
4083e54a169SMatthias Schwarzott 	if (len < 8) {
40977f887cdSMatthias Schwarzott 		dev_warn(&state->client->dev, "firmware header is missing\n");
4103e54a169SMatthias Schwarzott 		ret = -EINVAL;
4113e54a169SMatthias Schwarzott 		goto error;
4123e54a169SMatthias Schwarzott 	}
4133e54a169SMatthias Schwarzott 
4143e54a169SMatthias Schwarzott 	if (data[0] != 1 || data[1] != 0) {
41577f887cdSMatthias Schwarzott 		dev_warn(&state->client->dev, "firmware file version is wrong\n");
4163e54a169SMatthias Schwarzott 		ret = -EINVAL;
4173e54a169SMatthias Schwarzott 		goto error;
4183e54a169SMatthias Schwarzott 	}
4193e54a169SMatthias Schwarzott 
4203e54a169SMatthias Schwarzott 	patch_version = data[2];
4213e54a169SMatthias Schwarzott 	block_count = data[4];
4223e54a169SMatthias Schwarzott 	crc_expected = data[7] << 8 | data[6];
4233e54a169SMatthias Schwarzott 
4243e54a169SMatthias Schwarzott 	/* start uploading fw */
4253e54a169SMatthias Schwarzott 	/* boot/wdog status */
426814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_WDOG_AND_BOOT, 0x00);
4273e54a169SMatthias Schwarzott 	if (ret < 0)
4283e54a169SMatthias Schwarzott 		goto error;
4293e54a169SMatthias Schwarzott 	/* reset */
430814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_RST_ALL, 0x00);
4313e54a169SMatthias Schwarzott 	if (ret < 0)
4323e54a169SMatthias Schwarzott 		goto error;
4333e54a169SMatthias Schwarzott 	/* boot/wdog status */
434814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_WDOG_AND_BOOT, val);
4353e54a169SMatthias Schwarzott 	if (ret < 0)
4363e54a169SMatthias Schwarzott 		goto error;
4373e54a169SMatthias Schwarzott 
4383e54a169SMatthias Schwarzott 	/* enable reset on error */
439814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_EN_RST_ERROR, val);
4403e54a169SMatthias Schwarzott 	if (ret < 0)
4413e54a169SMatthias Schwarzott 		goto error;
442814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_EN_RST_ERROR, val);
4433e54a169SMatthias Schwarzott 	if (ret < 0)
4443e54a169SMatthias Schwarzott 		goto error;
445814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_EN_RST_ERROR, 0x02);
4463e54a169SMatthias Schwarzott 	if (ret < 0)
4473e54a169SMatthias Schwarzott 		goto error;
4483e54a169SMatthias Schwarzott 
4493e54a169SMatthias Schwarzott 	/* start right after the header */
4503e54a169SMatthias Schwarzott 	offset = 8;
4513e54a169SMatthias Schwarzott 
4527dbbb4bfSMatthias Schwarzott 	dev_info(&state->client->dev, "%s: extracted patch_version=0x%02x, block_count=0x%02x, crc_expected=0x%04x\n",
4537dbbb4bfSMatthias Schwarzott 		 __func__, patch_version, block_count, crc_expected);
4543e54a169SMatthias Schwarzott 
4553e54a169SMatthias Schwarzott 	ret = si2165_upload_firmware_block(state, data, len, &offset, 1);
4563e54a169SMatthias Schwarzott 	if (ret < 0)
4573e54a169SMatthias Schwarzott 		goto error;
4583e54a169SMatthias Schwarzott 
459814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_PATCH_VERSION, patch_version);
4603e54a169SMatthias Schwarzott 	if (ret < 0)
4613e54a169SMatthias Schwarzott 		goto error;
4623e54a169SMatthias Schwarzott 
4633e54a169SMatthias Schwarzott 	/* reset crc */
464814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_RST_CRC, 0x01);
4653e54a169SMatthias Schwarzott 	if (ret)
466ec73b9fdSChristian Engelmayer 		goto error;
4673e54a169SMatthias Schwarzott 
4683e54a169SMatthias Schwarzott 	ret = si2165_upload_firmware_block(state, data, len,
4693e54a169SMatthias Schwarzott 					   &offset, block_count);
4703e54a169SMatthias Schwarzott 	if (ret < 0) {
471aa155449SMatthias Schwarzott 		dev_err(&state->client->dev,
47277f887cdSMatthias Schwarzott 			"firmware could not be uploaded\n");
4733e54a169SMatthias Schwarzott 		goto error;
4743e54a169SMatthias Schwarzott 	}
4753e54a169SMatthias Schwarzott 
4763e54a169SMatthias Schwarzott 	/* read crc */
477814f86c9SMatthias Schwarzott 	ret = si2165_readreg16(state, REG_CRC, &val16);
4783e54a169SMatthias Schwarzott 	if (ret)
4793e54a169SMatthias Schwarzott 		goto error;
4803e54a169SMatthias Schwarzott 
4813e54a169SMatthias Schwarzott 	if (val16 != crc_expected) {
482aa155449SMatthias Schwarzott 		dev_err(&state->client->dev,
48377f887cdSMatthias Schwarzott 			"firmware crc mismatch %04x != %04x\n",
48477f887cdSMatthias Schwarzott 			val16, crc_expected);
4853e54a169SMatthias Schwarzott 		ret = -EINVAL;
4863e54a169SMatthias Schwarzott 		goto error;
4873e54a169SMatthias Schwarzott 	}
4883e54a169SMatthias Schwarzott 
4893e54a169SMatthias Schwarzott 	ret = si2165_upload_firmware_block(state, data, len, &offset, 5);
4903e54a169SMatthias Schwarzott 	if (ret)
4913e54a169SMatthias Schwarzott 		goto error;
4923e54a169SMatthias Schwarzott 
4933e54a169SMatthias Schwarzott 	if (len != offset) {
494aa155449SMatthias Schwarzott 		dev_err(&state->client->dev,
49577f887cdSMatthias Schwarzott 			"firmware len mismatch %04x != %04x\n",
49677f887cdSMatthias Schwarzott 			len, offset);
4973e54a169SMatthias Schwarzott 		ret = -EINVAL;
4983e54a169SMatthias Schwarzott 		goto error;
4993e54a169SMatthias Schwarzott 	}
5003e54a169SMatthias Schwarzott 
5013e54a169SMatthias Schwarzott 	/* reset watchdog error register */
502814f86c9SMatthias Schwarzott 	ret = si2165_writereg_mask8(state, REG_WDOG_AND_BOOT, 0x02, 0x02);
5033e54a169SMatthias Schwarzott 	if (ret < 0)
5043e54a169SMatthias Schwarzott 		goto error;
5053e54a169SMatthias Schwarzott 
5063e54a169SMatthias Schwarzott 	/* enable reset on error */
507814f86c9SMatthias Schwarzott 	ret = si2165_writereg_mask8(state, REG_EN_RST_ERROR, 0x01, 0x01);
5083e54a169SMatthias Schwarzott 	if (ret < 0)
5093e54a169SMatthias Schwarzott 		goto error;
5103e54a169SMatthias Schwarzott 
51177f887cdSMatthias Schwarzott 	dev_info(&state->client->dev, "fw load finished\n");
5123e54a169SMatthias Schwarzott 
5133e54a169SMatthias Schwarzott 	ret = 0;
5143e54a169SMatthias Schwarzott 	state->firmware_loaded = true;
5153e54a169SMatthias Schwarzott error:
5163e54a169SMatthias Schwarzott 	if (fw) {
5173e54a169SMatthias Schwarzott 		release_firmware(fw);
5183e54a169SMatthias Schwarzott 		fw = NULL;
5193e54a169SMatthias Schwarzott 	}
5203e54a169SMatthias Schwarzott 
5213e54a169SMatthias Schwarzott 	return ret;
5223e54a169SMatthias Schwarzott }
5233e54a169SMatthias Schwarzott 
si2165_init(struct dvb_frontend * fe)5243e54a169SMatthias Schwarzott static int si2165_init(struct dvb_frontend *fe)
5253e54a169SMatthias Schwarzott {
5263e54a169SMatthias Schwarzott 	int ret = 0;
5273e54a169SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
528c0675d0bSMatthias Schwarzott 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
5293e54a169SMatthias Schwarzott 	u8 val;
5303e54a169SMatthias Schwarzott 	u8 patch_version = 0x00;
5313e54a169SMatthias Schwarzott 
5321b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev, "%s: called\n", __func__);
5333e54a169SMatthias Schwarzott 
5343e54a169SMatthias Schwarzott 	/* powerup */
535814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_MODE, state->config.chip_mode);
5363e54a169SMatthias Schwarzott 	if (ret < 0)
5373e54a169SMatthias Schwarzott 		goto error;
5383e54a169SMatthias Schwarzott 	/* dsp_clock_enable */
539814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_DSP_CLOCK, 0x01);
5403e54a169SMatthias Schwarzott 	if (ret < 0)
5413e54a169SMatthias Schwarzott 		goto error;
542814f86c9SMatthias Schwarzott 	/* verify chip_mode */
543814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_CHIP_MODE, &val);
5443e54a169SMatthias Schwarzott 	if (ret < 0)
5453e54a169SMatthias Schwarzott 		goto error;
5463e54a169SMatthias Schwarzott 	if (val != state->config.chip_mode) {
54777f887cdSMatthias Schwarzott 		dev_err(&state->client->dev, "could not set chip_mode\n");
5483e54a169SMatthias Schwarzott 		return -EINVAL;
5493e54a169SMatthias Schwarzott 	}
5503e54a169SMatthias Schwarzott 
5513e54a169SMatthias Schwarzott 	/* agc */
552814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_AGC_IF_TRI, 0x00);
5533e54a169SMatthias Schwarzott 	if (ret < 0)
5543e54a169SMatthias Schwarzott 		goto error;
555814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_AGC_IF_SLR, 0x01);
5563e54a169SMatthias Schwarzott 	if (ret < 0)
5573e54a169SMatthias Schwarzott 		goto error;
558814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_AGC2_OUTPUT, 0x00);
5593e54a169SMatthias Schwarzott 	if (ret < 0)
5603e54a169SMatthias Schwarzott 		goto error;
561814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_AGC2_CLKDIV, 0x07);
5623e54a169SMatthias Schwarzott 	if (ret < 0)
5633e54a169SMatthias Schwarzott 		goto error;
5643e54a169SMatthias Schwarzott 	/* rssi pad */
565814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_RSSI_PAD_CTRL, 0x00);
5663e54a169SMatthias Schwarzott 	if (ret < 0)
5673e54a169SMatthias Schwarzott 		goto error;
568814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_RSSI_ENABLE, 0x00);
5693e54a169SMatthias Schwarzott 	if (ret < 0)
5703e54a169SMatthias Schwarzott 		goto error;
5713e54a169SMatthias Schwarzott 
5723e54a169SMatthias Schwarzott 	ret = si2165_init_pll(state);
5733e54a169SMatthias Schwarzott 	if (ret < 0)
5743e54a169SMatthias Schwarzott 		goto error;
5753e54a169SMatthias Schwarzott 
5763e54a169SMatthias Schwarzott 	/* enable chip_init */
577814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_INIT, 0x01);
5783e54a169SMatthias Schwarzott 	if (ret < 0)
5793e54a169SMatthias Schwarzott 		goto error;
5803e54a169SMatthias Schwarzott 	/* set start_init */
581814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_START_INIT, 0x01);
5823e54a169SMatthias Schwarzott 	if (ret < 0)
5833e54a169SMatthias Schwarzott 		goto error;
5843e54a169SMatthias Schwarzott 	ret = si2165_wait_init_done(state);
5853e54a169SMatthias Schwarzott 	if (ret < 0)
5863e54a169SMatthias Schwarzott 		goto error;
5873e54a169SMatthias Schwarzott 
5883e54a169SMatthias Schwarzott 	/* disable chip_init */
589814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_INIT, 0x00);
5903e54a169SMatthias Schwarzott 	if (ret < 0)
5913e54a169SMatthias Schwarzott 		goto error;
5923e54a169SMatthias Schwarzott 
593964b3727SMatthias Schwarzott 	/* ber_pkt - default 65535 */
594964b3727SMatthias Schwarzott 	ret = si2165_writereg16(state, REG_BER_PKT,
595964b3727SMatthias Schwarzott 				STATISTICS_PERIOD_PKT_COUNT);
5963e54a169SMatthias Schwarzott 	if (ret < 0)
5973e54a169SMatthias Schwarzott 		goto error;
5983e54a169SMatthias Schwarzott 
599814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_PATCH_VERSION, &patch_version);
6003e54a169SMatthias Schwarzott 	if (ret < 0)
6013e54a169SMatthias Schwarzott 		goto error;
6023e54a169SMatthias Schwarzott 
603814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_AUTO_RESET, 0x00);
6043e54a169SMatthias Schwarzott 	if (ret < 0)
6053e54a169SMatthias Schwarzott 		goto error;
6063e54a169SMatthias Schwarzott 
6073e54a169SMatthias Schwarzott 	/* dsp_addr_jump */
608814f86c9SMatthias Schwarzott 	ret = si2165_writereg32(state, REG_ADDR_JUMP, 0xf4000000);
6093e54a169SMatthias Schwarzott 	if (ret < 0)
6103e54a169SMatthias Schwarzott 		goto error;
6113e54a169SMatthias Schwarzott 	/* boot/wdog status */
612814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_WDOG_AND_BOOT, &val);
6133e54a169SMatthias Schwarzott 	if (ret < 0)
6143e54a169SMatthias Schwarzott 		goto error;
6153e54a169SMatthias Schwarzott 
6163e54a169SMatthias Schwarzott 	if (patch_version == 0x00) {
6173e54a169SMatthias Schwarzott 		ret = si2165_upload_firmware(state);
6183e54a169SMatthias Schwarzott 		if (ret < 0)
6193e54a169SMatthias Schwarzott 			goto error;
6203e54a169SMatthias Schwarzott 	}
6213e54a169SMatthias Schwarzott 
62275d62fc0SMatthias Schwarzott 	/* ts output config */
623814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_TS_DATA_MODE, 0x20);
62475d62fc0SMatthias Schwarzott 	if (ret < 0)
62575d62fc0SMatthias Schwarzott 		return ret;
626814f86c9SMatthias Schwarzott 	ret = si2165_writereg16(state, REG_TS_TRI, 0x00fe);
62775d62fc0SMatthias Schwarzott 	if (ret < 0)
62875d62fc0SMatthias Schwarzott 		return ret;
629814f86c9SMatthias Schwarzott 	ret = si2165_writereg24(state, REG_TS_SLR, 0x555555);
63075d62fc0SMatthias Schwarzott 	if (ret < 0)
63175d62fc0SMatthias Schwarzott 		return ret;
632814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_TS_CLK_MODE, 0x01);
63375d62fc0SMatthias Schwarzott 	if (ret < 0)
63475d62fc0SMatthias Schwarzott 		return ret;
635ec278f87SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_TS_PARALLEL_MODE, 0x00);
636ec278f87SMatthias Schwarzott 	if (ret < 0)
637ec278f87SMatthias Schwarzott 		return ret;
63875d62fc0SMatthias Schwarzott 
639c0675d0bSMatthias Schwarzott 	c = &state->fe.dtv_property_cache;
640c0675d0bSMatthias Schwarzott 	c->cnr.len = 1;
641c0675d0bSMatthias Schwarzott 	c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
642964b3727SMatthias Schwarzott 	c->post_bit_error.len = 1;
643964b3727SMatthias Schwarzott 	c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
644964b3727SMatthias Schwarzott 	c->post_bit_count.len = 1;
645964b3727SMatthias Schwarzott 	c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
646c0675d0bSMatthias Schwarzott 
6473e54a169SMatthias Schwarzott 	return 0;
6483e54a169SMatthias Schwarzott error:
6493e54a169SMatthias Schwarzott 	return ret;
6503e54a169SMatthias Schwarzott }
6513e54a169SMatthias Schwarzott 
si2165_sleep(struct dvb_frontend * fe)6523e54a169SMatthias Schwarzott static int si2165_sleep(struct dvb_frontend *fe)
6533e54a169SMatthias Schwarzott {
6543e54a169SMatthias Schwarzott 	int ret;
6553e54a169SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
6563e54a169SMatthias Schwarzott 
6573e54a169SMatthias Schwarzott 	/* dsp clock disable */
658814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_DSP_CLOCK, 0x00);
6593e54a169SMatthias Schwarzott 	if (ret < 0)
6603e54a169SMatthias Schwarzott 		return ret;
6613e54a169SMatthias Schwarzott 	/* chip mode */
662814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_MODE, SI2165_MODE_OFF);
6633e54a169SMatthias Schwarzott 	if (ret < 0)
6643e54a169SMatthias Schwarzott 		return ret;
6653e54a169SMatthias Schwarzott 	return 0;
6663e54a169SMatthias Schwarzott }
6673e54a169SMatthias Schwarzott 
si2165_read_status(struct dvb_frontend * fe,enum fe_status * status)6680df289a2SMauro Carvalho Chehab static int si2165_read_status(struct dvb_frontend *fe, enum fe_status *status)
6693e54a169SMatthias Schwarzott {
6703e54a169SMatthias Schwarzott 	int ret;
6711e5fde1bSMatthias Schwarzott 	u8 u8tmp;
672c0675d0bSMatthias Schwarzott 	u32 u32tmp;
6733e54a169SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
674c0675d0bSMatthias Schwarzott 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
675c0675d0bSMatthias Schwarzott 	u32 delsys = c->delivery_system;
6763e54a169SMatthias Schwarzott 
6771e5fde1bSMatthias Schwarzott 	*status = 0;
6783e54a169SMatthias Schwarzott 
6791e5fde1bSMatthias Schwarzott 	switch (delsys) {
6801e5fde1bSMatthias Schwarzott 	case SYS_DVBT:
6811e5fde1bSMatthias Schwarzott 		/* check fast signal type */
6821e5fde1bSMatthias Schwarzott 		ret = si2165_readreg8(state, REG_CHECK_SIGNAL, &u8tmp);
6833e54a169SMatthias Schwarzott 		if (ret < 0)
6843e54a169SMatthias Schwarzott 			return ret;
6851e5fde1bSMatthias Schwarzott 		switch (u8tmp & 0x3) {
6861e5fde1bSMatthias Schwarzott 		case 0: /* searching */
6871e5fde1bSMatthias Schwarzott 		case 1: /* nothing */
6881e5fde1bSMatthias Schwarzott 			break;
6891e5fde1bSMatthias Schwarzott 		case 2: /* digital signal */
6901e5fde1bSMatthias Schwarzott 			*status |= FE_HAS_SIGNAL | FE_HAS_CARRIER;
6911e5fde1bSMatthias Schwarzott 			break;
6921e5fde1bSMatthias Schwarzott 		}
6931e5fde1bSMatthias Schwarzott 		break;
6941e5fde1bSMatthias Schwarzott 	case SYS_DVBC_ANNEX_A:
6951e5fde1bSMatthias Schwarzott 		/* check packet sync lock */
6961e5fde1bSMatthias Schwarzott 		ret = si2165_readreg8(state, REG_PS_LOCK, &u8tmp);
6971e5fde1bSMatthias Schwarzott 		if (ret < 0)
6981e5fde1bSMatthias Schwarzott 			return ret;
6991e5fde1bSMatthias Schwarzott 		if (u8tmp & 0x01) {
7001e5fde1bSMatthias Schwarzott 			*status |= FE_HAS_SIGNAL;
7011e5fde1bSMatthias Schwarzott 			*status |= FE_HAS_CARRIER;
7021e5fde1bSMatthias Schwarzott 			*status |= FE_HAS_VITERBI;
7031e5fde1bSMatthias Schwarzott 			*status |= FE_HAS_SYNC;
7041e5fde1bSMatthias Schwarzott 		}
7051e5fde1bSMatthias Schwarzott 		break;
7061e5fde1bSMatthias Schwarzott 	}
7071e5fde1bSMatthias Schwarzott 
7081e5fde1bSMatthias Schwarzott 	/* check fec_lock */
7091e5fde1bSMatthias Schwarzott 	ret = si2165_readreg8(state, REG_FEC_LOCK, &u8tmp);
7101e5fde1bSMatthias Schwarzott 	if (ret < 0)
7111e5fde1bSMatthias Schwarzott 		return ret;
7121e5fde1bSMatthias Schwarzott 	if (u8tmp & 0x01) {
7133e54a169SMatthias Schwarzott 		*status |= FE_HAS_SIGNAL;
7143e54a169SMatthias Schwarzott 		*status |= FE_HAS_CARRIER;
7153e54a169SMatthias Schwarzott 		*status |= FE_HAS_VITERBI;
7163e54a169SMatthias Schwarzott 		*status |= FE_HAS_SYNC;
7173e54a169SMatthias Schwarzott 		*status |= FE_HAS_LOCK;
7183e54a169SMatthias Schwarzott 	}
7193e54a169SMatthias Schwarzott 
720c0675d0bSMatthias Schwarzott 	/* CNR */
721c0675d0bSMatthias Schwarzott 	if (delsys == SYS_DVBC_ANNEX_A && *status & FE_HAS_VITERBI) {
722c0675d0bSMatthias Schwarzott 		ret = si2165_readreg24(state, REG_C_N, &u32tmp);
723c0675d0bSMatthias Schwarzott 		if (ret < 0)
724c0675d0bSMatthias Schwarzott 			return ret;
725c0675d0bSMatthias Schwarzott 		/*
726c0675d0bSMatthias Schwarzott 		 * svalue =
727c0675d0bSMatthias Schwarzott 		 * 1000 * c_n/dB =
728c0675d0bSMatthias Schwarzott 		 * 1000 * 10 * log10(2^24 / regval) =
729c0675d0bSMatthias Schwarzott 		 * 1000 * 10 * (log10(2^24) - log10(regval)) =
730c0675d0bSMatthias Schwarzott 		 * 1000 * 10 * (intlog10(2^24) - intlog10(regval)) / 2^24
731c0675d0bSMatthias Schwarzott 		 *
732c0675d0bSMatthias Schwarzott 		 * intlog10(x) = log10(x) * 2^24
733c0675d0bSMatthias Schwarzott 		 * intlog10(2^24) = log10(2^24) * 2^24 = 121210686
734c0675d0bSMatthias Schwarzott 		 */
735c0675d0bSMatthias Schwarzott 		u32tmp = (1000 * 10 * (121210686 - (u64)intlog10(u32tmp)))
736c0675d0bSMatthias Schwarzott 				>> 24;
737c0675d0bSMatthias Schwarzott 		c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
738c0675d0bSMatthias Schwarzott 		c->cnr.stat[0].svalue = u32tmp;
739c0675d0bSMatthias Schwarzott 	} else
740c0675d0bSMatthias Schwarzott 		c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
741c0675d0bSMatthias Schwarzott 
742964b3727SMatthias Schwarzott 	/* BER */
743964b3727SMatthias Schwarzott 	if (*status & FE_HAS_VITERBI) {
744964b3727SMatthias Schwarzott 		if (c->post_bit_error.stat[0].scale == FE_SCALE_NOT_AVAILABLE) {
745964b3727SMatthias Schwarzott 			/* start new sampling period to get rid of old data*/
746964b3727SMatthias Schwarzott 			ret = si2165_writereg8(state, REG_BER_RST, 0x01);
747964b3727SMatthias Schwarzott 			if (ret < 0)
748964b3727SMatthias Schwarzott 				return ret;
749964b3727SMatthias Schwarzott 
750964b3727SMatthias Schwarzott 			/* set scale to enter read code on next call */
751964b3727SMatthias Schwarzott 			c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
752964b3727SMatthias Schwarzott 			c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
753964b3727SMatthias Schwarzott 			c->post_bit_error.stat[0].uvalue = 0;
754964b3727SMatthias Schwarzott 			c->post_bit_count.stat[0].uvalue = 0;
755964b3727SMatthias Schwarzott 
756e9c7d19aSMatthias Schwarzott 			/*
757e9c7d19aSMatthias Schwarzott 			 * reset DVBv3 value to deliver a good result
758e9c7d19aSMatthias Schwarzott 			 * for the first call
759e9c7d19aSMatthias Schwarzott 			 */
760e9c7d19aSMatthias Schwarzott 			state->ber_prev = 0;
761e9c7d19aSMatthias Schwarzott 
762964b3727SMatthias Schwarzott 		} else {
763964b3727SMatthias Schwarzott 			ret = si2165_readreg8(state, REG_BER_AVAIL, &u8tmp);
764964b3727SMatthias Schwarzott 			if (ret < 0)
765964b3727SMatthias Schwarzott 				return ret;
766964b3727SMatthias Schwarzott 
767964b3727SMatthias Schwarzott 			if (u8tmp & 1) {
768964b3727SMatthias Schwarzott 				u32 biterrcnt;
769964b3727SMatthias Schwarzott 
770964b3727SMatthias Schwarzott 				ret = si2165_readreg24(state, REG_BER_BIT,
771964b3727SMatthias Schwarzott 							&biterrcnt);
772964b3727SMatthias Schwarzott 				if (ret < 0)
773964b3727SMatthias Schwarzott 					return ret;
774964b3727SMatthias Schwarzott 
775964b3727SMatthias Schwarzott 				c->post_bit_error.stat[0].uvalue +=
776964b3727SMatthias Schwarzott 					biterrcnt;
777964b3727SMatthias Schwarzott 				c->post_bit_count.stat[0].uvalue +=
778964b3727SMatthias Schwarzott 					STATISTICS_PERIOD_BIT_COUNT;
779964b3727SMatthias Schwarzott 
780964b3727SMatthias Schwarzott 				/* start new sampling period */
781964b3727SMatthias Schwarzott 				ret = si2165_writereg8(state,
782964b3727SMatthias Schwarzott 							REG_BER_RST, 0x01);
783964b3727SMatthias Schwarzott 				if (ret < 0)
784964b3727SMatthias Schwarzott 					return ret;
785964b3727SMatthias Schwarzott 
786964b3727SMatthias Schwarzott 				dev_dbg(&state->client->dev,
787964b3727SMatthias Schwarzott 					"post_bit_error=%u post_bit_count=%u\n",
788964b3727SMatthias Schwarzott 					biterrcnt, STATISTICS_PERIOD_BIT_COUNT);
789964b3727SMatthias Schwarzott 			}
790964b3727SMatthias Schwarzott 		}
791964b3727SMatthias Schwarzott 	} else {
792964b3727SMatthias Schwarzott 		c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
793964b3727SMatthias Schwarzott 		c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
794964b3727SMatthias Schwarzott 	}
795964b3727SMatthias Schwarzott 
7963e54a169SMatthias Schwarzott 	return 0;
7973e54a169SMatthias Schwarzott }
7983e54a169SMatthias Schwarzott 
si2165_read_snr(struct dvb_frontend * fe,u16 * snr)7992e687a6dSMatthias Schwarzott static int si2165_read_snr(struct dvb_frontend *fe, u16 *snr)
8002e687a6dSMatthias Schwarzott {
8012e687a6dSMatthias Schwarzott 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
8022e687a6dSMatthias Schwarzott 
8032e687a6dSMatthias Schwarzott 	if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
8042e687a6dSMatthias Schwarzott 		*snr = div_s64(c->cnr.stat[0].svalue, 100);
8052e687a6dSMatthias Schwarzott 	else
8062e687a6dSMatthias Schwarzott 		*snr = 0;
8072e687a6dSMatthias Schwarzott 	return 0;
8082e687a6dSMatthias Schwarzott }
8092e687a6dSMatthias Schwarzott 
si2165_read_ber(struct dvb_frontend * fe,u32 * ber)810e9c7d19aSMatthias Schwarzott static int si2165_read_ber(struct dvb_frontend *fe, u32 *ber)
811e9c7d19aSMatthias Schwarzott {
812e9c7d19aSMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
813e9c7d19aSMatthias Schwarzott 	struct dtv_frontend_properties *c = &fe->dtv_property_cache;
814e9c7d19aSMatthias Schwarzott 
815e9c7d19aSMatthias Schwarzott 	if (c->post_bit_error.stat[0].scale != FE_SCALE_COUNTER) {
816e9c7d19aSMatthias Schwarzott 		*ber = 0;
817e9c7d19aSMatthias Schwarzott 		return 0;
818e9c7d19aSMatthias Schwarzott 	}
819e9c7d19aSMatthias Schwarzott 
820e9c7d19aSMatthias Schwarzott 	*ber = c->post_bit_error.stat[0].uvalue - state->ber_prev;
821e9c7d19aSMatthias Schwarzott 	state->ber_prev = c->post_bit_error.stat[0].uvalue;
822e9c7d19aSMatthias Schwarzott 
823e9c7d19aSMatthias Schwarzott 	return 0;
824e9c7d19aSMatthias Schwarzott }
825e9c7d19aSMatthias Schwarzott 
si2165_set_oversamp(struct si2165_state * state,u32 dvb_rate)8263e54a169SMatthias Schwarzott static int si2165_set_oversamp(struct si2165_state *state, u32 dvb_rate)
8273e54a169SMatthias Schwarzott {
8283e54a169SMatthias Schwarzott 	u64 oversamp;
8293e54a169SMatthias Schwarzott 	u32 reg_value;
8303e54a169SMatthias Schwarzott 
8312df9dda0SMatthias Schwarzott 	if (!dvb_rate)
8322df9dda0SMatthias Schwarzott 		return -EINVAL;
8332df9dda0SMatthias Schwarzott 
8343e54a169SMatthias Schwarzott 	oversamp = si2165_get_fe_clk(state);
8353e54a169SMatthias Schwarzott 	oversamp <<= 23;
8363e54a169SMatthias Schwarzott 	do_div(oversamp, dvb_rate);
8373e54a169SMatthias Schwarzott 	reg_value = oversamp & 0x3fffffff;
8383e54a169SMatthias Schwarzott 
8391b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev, "Write oversamp=%#x\n", reg_value);
840814f86c9SMatthias Schwarzott 	return si2165_writereg32(state, REG_OVERSAMP, reg_value);
8413e54a169SMatthias Schwarzott }
8423e54a169SMatthias Schwarzott 
si2165_set_if_freq_shift(struct si2165_state * state)843542fb3c5SMatthias Schwarzott static int si2165_set_if_freq_shift(struct si2165_state *state)
8443e54a169SMatthias Schwarzott {
845542fb3c5SMatthias Schwarzott 	struct dvb_frontend *fe = &state->fe;
8463e54a169SMatthias Schwarzott 	u64 if_freq_shift;
8473e54a169SMatthias Schwarzott 	s32 reg_value = 0;
8483e54a169SMatthias Schwarzott 	u32 fe_clk = si2165_get_fe_clk(state);
849542fb3c5SMatthias Schwarzott 	u32 IF = 0;
8503e54a169SMatthias Schwarzott 
851542fb3c5SMatthias Schwarzott 	if (!fe->ops.tuner_ops.get_if_frequency) {
852aa155449SMatthias Schwarzott 		dev_err(&state->client->dev,
85377f887cdSMatthias Schwarzott 			"Error: get_if_frequency() not defined at tuner. Can't work without it!\n");
854542fb3c5SMatthias Schwarzott 		return -EINVAL;
855542fb3c5SMatthias Schwarzott 	}
856542fb3c5SMatthias Schwarzott 
8572df9dda0SMatthias Schwarzott 	if (!fe_clk)
8582df9dda0SMatthias Schwarzott 		return -EINVAL;
8592df9dda0SMatthias Schwarzott 
860542fb3c5SMatthias Schwarzott 	fe->ops.tuner_ops.get_if_frequency(fe, &IF);
8613e54a169SMatthias Schwarzott 	if_freq_shift = IF;
8623e54a169SMatthias Schwarzott 	if_freq_shift <<= 29;
8633e54a169SMatthias Schwarzott 
8643e54a169SMatthias Schwarzott 	do_div(if_freq_shift, fe_clk);
8653e54a169SMatthias Schwarzott 	reg_value = (s32)if_freq_shift;
8663e54a169SMatthias Schwarzott 
8673e54a169SMatthias Schwarzott 	if (state->config.inversion)
8683e54a169SMatthias Schwarzott 		reg_value = -reg_value;
8693e54a169SMatthias Schwarzott 
8703e54a169SMatthias Schwarzott 	reg_value = reg_value & 0x1fffffff;
8713e54a169SMatthias Schwarzott 
8723e54a169SMatthias Schwarzott 	/* if_freq_shift, usbdump contained 0x023ee08f; */
873814f86c9SMatthias Schwarzott 	return si2165_writereg32(state, REG_IF_FREQ_SHIFT, reg_value);
8743e54a169SMatthias Schwarzott }
8753e54a169SMatthias Schwarzott 
87625e73753SMatthias Schwarzott static const struct si2165_reg_value_pair dvbt_regs[] = {
87725e73753SMatthias Schwarzott 	/* standard = DVB-T */
878814f86c9SMatthias Schwarzott 	{ REG_DVB_STANDARD, 0x01 },
87925e73753SMatthias Schwarzott 	/* impulsive_noise_remover */
880814f86c9SMatthias Schwarzott 	{ REG_IMPULSIVE_NOISE_REM, 0x01 },
881814f86c9SMatthias Schwarzott 	{ REG_AUTO_RESET, 0x00 },
88225e73753SMatthias Schwarzott 	/* agc2 */
883814f86c9SMatthias Schwarzott 	{ REG_AGC2_MIN, 0x41 },
884814f86c9SMatthias Schwarzott 	{ REG_AGC2_KACQ, 0x0e },
885814f86c9SMatthias Schwarzott 	{ REG_AGC2_KLOC, 0x10 },
88625e73753SMatthias Schwarzott 	/* agc */
887814f86c9SMatthias Schwarzott 	{ REG_AGC_UNFREEZE_THR, 0x03 },
888814f86c9SMatthias Schwarzott 	{ REG_AGC_CRESTF_DBX8, 0x78 },
88925e73753SMatthias Schwarzott 	/* agc */
890814f86c9SMatthias Schwarzott 	{ REG_AAF_CRESTF_DBX8, 0x78 },
891814f86c9SMatthias Schwarzott 	{ REG_ACI_CRESTF_DBX8, 0x68 },
89225e73753SMatthias Schwarzott 	/* freq_sync_range */
893814f86c9SMatthias Schwarzott 	REG16(REG_FREQ_SYNC_RANGE, 0x0064),
89425e73753SMatthias Schwarzott 	/* gp_reg0 */
895814f86c9SMatthias Schwarzott 	{ REG_GP_REG0_MSB, 0x00 }
89625e73753SMatthias Schwarzott };
89725e73753SMatthias Schwarzott 
si2165_set_frontend_dvbt(struct dvb_frontend * fe)8983b0c9807SMatthias Schwarzott static int si2165_set_frontend_dvbt(struct dvb_frontend *fe)
8993e54a169SMatthias Schwarzott {
9003e54a169SMatthias Schwarzott 	int ret;
9013e54a169SMatthias Schwarzott 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
9023e54a169SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
9033e54a169SMatthias Schwarzott 	u32 dvb_rate = 0;
9043e54a169SMatthias Schwarzott 	u16 bw10k;
9057655a3aeSMatthias Schwarzott 	u32 bw_hz = p->bandwidth_hz;
9063e54a169SMatthias Schwarzott 
9071b54da77SMatthias Schwarzott 	dev_dbg(&state->client->dev, "%s: called\n", __func__);
9083e54a169SMatthias Schwarzott 
9093e54a169SMatthias Schwarzott 	if (!state->has_dvbt)
9103e54a169SMatthias Schwarzott 		return -EINVAL;
9113e54a169SMatthias Schwarzott 
9127655a3aeSMatthias Schwarzott 	/* no bandwidth auto-detection */
9137655a3aeSMatthias Schwarzott 	if (bw_hz == 0)
9147655a3aeSMatthias Schwarzott 		return -EINVAL;
9157655a3aeSMatthias Schwarzott 
9167655a3aeSMatthias Schwarzott 	dvb_rate = bw_hz * 8 / 7;
9177655a3aeSMatthias Schwarzott 	bw10k = bw_hz / 10000;
9183e54a169SMatthias Schwarzott 
9193e54a169SMatthias Schwarzott 	ret = si2165_adjust_pll_divl(state, 12);
9203e54a169SMatthias Schwarzott 	if (ret < 0)
9213e54a169SMatthias Schwarzott 		return ret;
9223e54a169SMatthias Schwarzott 
9233e54a169SMatthias Schwarzott 	/* bandwidth in 10KHz steps */
924814f86c9SMatthias Schwarzott 	ret = si2165_writereg16(state, REG_T_BANDWIDTH, bw10k);
9253e54a169SMatthias Schwarzott 	if (ret < 0)
9263e54a169SMatthias Schwarzott 		return ret;
9273e54a169SMatthias Schwarzott 	ret = si2165_set_oversamp(state, dvb_rate);
9283e54a169SMatthias Schwarzott 	if (ret < 0)
9293e54a169SMatthias Schwarzott 		return ret;
93025e73753SMatthias Schwarzott 
93125e73753SMatthias Schwarzott 	ret = si2165_write_reg_list(state, dvbt_regs, ARRAY_SIZE(dvbt_regs));
9323e54a169SMatthias Schwarzott 	if (ret < 0)
9333e54a169SMatthias Schwarzott 		return ret;
93425e73753SMatthias Schwarzott 
9353b0c9807SMatthias Schwarzott 	return 0;
9363b0c9807SMatthias Schwarzott }
9373b0c9807SMatthias Schwarzott 
93894c17334SMatthias Schwarzott static const struct si2165_reg_value_pair dvbc_regs[] = {
93994c17334SMatthias Schwarzott 	/* standard = DVB-C */
940814f86c9SMatthias Schwarzott 	{ REG_DVB_STANDARD, 0x05 },
94194c17334SMatthias Schwarzott 
94294c17334SMatthias Schwarzott 	/* agc2 */
943814f86c9SMatthias Schwarzott 	{ REG_AGC2_MIN, 0x50 },
944814f86c9SMatthias Schwarzott 	{ REG_AGC2_KACQ, 0x0e },
945814f86c9SMatthias Schwarzott 	{ REG_AGC2_KLOC, 0x10 },
94694c17334SMatthias Schwarzott 	/* agc */
947814f86c9SMatthias Schwarzott 	{ REG_AGC_UNFREEZE_THR, 0x03 },
948814f86c9SMatthias Schwarzott 	{ REG_AGC_CRESTF_DBX8, 0x68 },
94994c17334SMatthias Schwarzott 	/* agc */
950814f86c9SMatthias Schwarzott 	{ REG_AAF_CRESTF_DBX8, 0x68 },
951814f86c9SMatthias Schwarzott 	{ REG_ACI_CRESTF_DBX8, 0x50 },
95294c17334SMatthias Schwarzott 
953814f86c9SMatthias Schwarzott 	{ REG_EQ_AUTO_CONTROL, 0x0d },
95494c17334SMatthias Schwarzott 
955814f86c9SMatthias Schwarzott 	{ REG_KP_LOCK, 0x05 },
956814f86c9SMatthias Schwarzott 	{ REG_CENTRAL_TAP, 0x09 },
957814f86c9SMatthias Schwarzott 	REG16(REG_UNKNOWN_350, 0x3e80),
95894c17334SMatthias Schwarzott 
959814f86c9SMatthias Schwarzott 	{ REG_AUTO_RESET, 0x01 },
960814f86c9SMatthias Schwarzott 	REG16(REG_UNKNOWN_24C, 0x0000),
961814f86c9SMatthias Schwarzott 	REG16(REG_UNKNOWN_27C, 0x0000),
962814f86c9SMatthias Schwarzott 	{ REG_SWEEP_STEP, 0x03 },
963814f86c9SMatthias Schwarzott 	{ REG_AGC_IF_TRI, 0x00 },
96494c17334SMatthias Schwarzott };
96594c17334SMatthias Schwarzott 
si2165_set_frontend_dvbc(struct dvb_frontend * fe)96694c17334SMatthias Schwarzott static int si2165_set_frontend_dvbc(struct dvb_frontend *fe)
96794c17334SMatthias Schwarzott {
96894c17334SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
96994c17334SMatthias Schwarzott 	int ret;
97094c17334SMatthias Schwarzott 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
97194c17334SMatthias Schwarzott 	const u32 dvb_rate = p->symbol_rate;
972548b1f94SMatthias Schwarzott 	u8 u8tmp;
97394c17334SMatthias Schwarzott 
97494c17334SMatthias Schwarzott 	if (!state->has_dvbc)
97594c17334SMatthias Schwarzott 		return -EINVAL;
97694c17334SMatthias Schwarzott 
97794c17334SMatthias Schwarzott 	if (dvb_rate == 0)
97894c17334SMatthias Schwarzott 		return -EINVAL;
97994c17334SMatthias Schwarzott 
98094c17334SMatthias Schwarzott 	ret = si2165_adjust_pll_divl(state, 14);
98194c17334SMatthias Schwarzott 	if (ret < 0)
98294c17334SMatthias Schwarzott 		return ret;
98394c17334SMatthias Schwarzott 
98494c17334SMatthias Schwarzott 	/* Oversampling */
98594c17334SMatthias Schwarzott 	ret = si2165_set_oversamp(state, dvb_rate);
98694c17334SMatthias Schwarzott 	if (ret < 0)
98794c17334SMatthias Schwarzott 		return ret;
98894c17334SMatthias Schwarzott 
989548b1f94SMatthias Schwarzott 	switch (p->modulation) {
990548b1f94SMatthias Schwarzott 	case QPSK:
991548b1f94SMatthias Schwarzott 		u8tmp = 0x3;
992548b1f94SMatthias Schwarzott 		break;
993548b1f94SMatthias Schwarzott 	case QAM_16:
994548b1f94SMatthias Schwarzott 		u8tmp = 0x7;
995548b1f94SMatthias Schwarzott 		break;
996548b1f94SMatthias Schwarzott 	case QAM_32:
997548b1f94SMatthias Schwarzott 		u8tmp = 0x8;
998548b1f94SMatthias Schwarzott 		break;
999548b1f94SMatthias Schwarzott 	case QAM_64:
1000548b1f94SMatthias Schwarzott 		u8tmp = 0x9;
1001548b1f94SMatthias Schwarzott 		break;
1002548b1f94SMatthias Schwarzott 	case QAM_128:
1003548b1f94SMatthias Schwarzott 		u8tmp = 0xa;
1004548b1f94SMatthias Schwarzott 		break;
1005548b1f94SMatthias Schwarzott 	case QAM_256:
1006548b1f94SMatthias Schwarzott 	default:
1007548b1f94SMatthias Schwarzott 		u8tmp = 0xb;
1008548b1f94SMatthias Schwarzott 		break;
1009548b1f94SMatthias Schwarzott 	}
1010548b1f94SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_REQ_CONSTELLATION, u8tmp);
1011548b1f94SMatthias Schwarzott 	if (ret < 0)
1012548b1f94SMatthias Schwarzott 		return ret;
1013548b1f94SMatthias Schwarzott 
1014f4d90518SMatthias Schwarzott 	ret = si2165_writereg32(state, REG_LOCK_TIMEOUT, 0x007a1200);
101594c17334SMatthias Schwarzott 	if (ret < 0)
101694c17334SMatthias Schwarzott 		return ret;
101794c17334SMatthias Schwarzott 
101894c17334SMatthias Schwarzott 	ret = si2165_write_reg_list(state, dvbc_regs, ARRAY_SIZE(dvbc_regs));
101994c17334SMatthias Schwarzott 	if (ret < 0)
102094c17334SMatthias Schwarzott 		return ret;
102194c17334SMatthias Schwarzott 
102294c17334SMatthias Schwarzott 	return 0;
102394c17334SMatthias Schwarzott }
102494c17334SMatthias Schwarzott 
1025814f86c9SMatthias Schwarzott static const struct si2165_reg_value_pair adc_rewrite[] = {
1026814f86c9SMatthias Schwarzott 	{ REG_ADC_RI1, 0x46 },
1027814f86c9SMatthias Schwarzott 	{ REG_ADC_RI3, 0x00 },
1028814f86c9SMatthias Schwarzott 	{ REG_ADC_RI5, 0x0a },
1029814f86c9SMatthias Schwarzott 	{ REG_ADC_RI6, 0xff },
1030814f86c9SMatthias Schwarzott 	{ REG_ADC_RI8, 0x70 }
10313b0c9807SMatthias Schwarzott };
10323b0c9807SMatthias Schwarzott 
si2165_set_frontend(struct dvb_frontend * fe)10333b0c9807SMatthias Schwarzott static int si2165_set_frontend(struct dvb_frontend *fe)
10343b0c9807SMatthias Schwarzott {
10353b0c9807SMatthias Schwarzott 	struct si2165_state *state = fe->demodulator_priv;
10363b0c9807SMatthias Schwarzott 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
10373b0c9807SMatthias Schwarzott 	u32 delsys = p->delivery_system;
10383b0c9807SMatthias Schwarzott 	int ret;
10393b0c9807SMatthias Schwarzott 	u8 val[3];
10403b0c9807SMatthias Schwarzott 
10413b0c9807SMatthias Schwarzott 	/* initial setting of if freq shift */
10423b0c9807SMatthias Schwarzott 	ret = si2165_set_if_freq_shift(state);
10433b0c9807SMatthias Schwarzott 	if (ret < 0)
10443b0c9807SMatthias Schwarzott 		return ret;
10453b0c9807SMatthias Schwarzott 
10463b0c9807SMatthias Schwarzott 	switch (delsys) {
10473b0c9807SMatthias Schwarzott 	case SYS_DVBT:
10483b0c9807SMatthias Schwarzott 		ret = si2165_set_frontend_dvbt(fe);
10493b0c9807SMatthias Schwarzott 		if (ret < 0)
10503b0c9807SMatthias Schwarzott 			return ret;
10513b0c9807SMatthias Schwarzott 		break;
105294c17334SMatthias Schwarzott 	case SYS_DVBC_ANNEX_A:
105394c17334SMatthias Schwarzott 		ret = si2165_set_frontend_dvbc(fe);
105494c17334SMatthias Schwarzott 		if (ret < 0)
105594c17334SMatthias Schwarzott 			return ret;
105694c17334SMatthias Schwarzott 		break;
10573b0c9807SMatthias Schwarzott 	default:
10583b0c9807SMatthias Schwarzott 		return -EINVAL;
10593b0c9807SMatthias Schwarzott 	}
10603b0c9807SMatthias Schwarzott 
10613e54a169SMatthias Schwarzott 	/* dsp_addr_jump */
1062814f86c9SMatthias Schwarzott 	ret = si2165_writereg32(state, REG_ADDR_JUMP, 0xf4000000);
10633e54a169SMatthias Schwarzott 	if (ret < 0)
10643e54a169SMatthias Schwarzott 		return ret;
10653e54a169SMatthias Schwarzott 
10663e54a169SMatthias Schwarzott 	if (fe->ops.tuner_ops.set_params)
10673e54a169SMatthias Schwarzott 		fe->ops.tuner_ops.set_params(fe);
10683e54a169SMatthias Schwarzott 
10693e54a169SMatthias Schwarzott 	/* recalc if_freq_shift if IF might has changed */
1070542fb3c5SMatthias Schwarzott 	ret = si2165_set_if_freq_shift(state);
10713e54a169SMatthias Schwarzott 	if (ret < 0)
10723e54a169SMatthias Schwarzott 		return ret;
10733e54a169SMatthias Schwarzott 
10743e54a169SMatthias Schwarzott 	/* boot/wdog status */
1075814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_WDOG_AND_BOOT, val);
10763e54a169SMatthias Schwarzott 	if (ret < 0)
10773e54a169SMatthias Schwarzott 		return ret;
1078814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_WDOG_AND_BOOT, 0x00);
10793e54a169SMatthias Schwarzott 	if (ret < 0)
10803e54a169SMatthias Schwarzott 		return ret;
10813b0c9807SMatthias Schwarzott 
10823e54a169SMatthias Schwarzott 	/* reset all */
1083814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_RST_ALL, 0x00);
10843e54a169SMatthias Schwarzott 	if (ret < 0)
10853e54a169SMatthias Schwarzott 		return ret;
10863e54a169SMatthias Schwarzott 	/* gp_reg0 */
1087814f86c9SMatthias Schwarzott 	ret = si2165_writereg32(state, REG_GP_REG0_LSB, 0x00000000);
10883e54a169SMatthias Schwarzott 	if (ret < 0)
10893e54a169SMatthias Schwarzott 		return ret;
1090eae56684SMatthias Schwarzott 
1091eae56684SMatthias Schwarzott 	/* write adc values after each reset*/
1092814f86c9SMatthias Schwarzott 	ret = si2165_write_reg_list(state, adc_rewrite,
1093814f86c9SMatthias Schwarzott 				    ARRAY_SIZE(adc_rewrite));
1094eae56684SMatthias Schwarzott 	if (ret < 0)
1095eae56684SMatthias Schwarzott 		return ret;
1096eae56684SMatthias Schwarzott 
10973e54a169SMatthias Schwarzott 	/* start_synchro */
1098814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_START_SYNCHRO, 0x01);
10993e54a169SMatthias Schwarzott 	if (ret < 0)
11003e54a169SMatthias Schwarzott 		return ret;
11013e54a169SMatthias Schwarzott 	/* boot/wdog status */
1102814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_WDOG_AND_BOOT, val);
11033e54a169SMatthias Schwarzott 	if (ret < 0)
11043e54a169SMatthias Schwarzott 		return ret;
11053e54a169SMatthias Schwarzott 
11063e54a169SMatthias Schwarzott 	return 0;
11073e54a169SMatthias Schwarzott }
11083e54a169SMatthias Schwarzott 
1109bd336e63SMax Kellermann static const struct dvb_frontend_ops si2165_ops = {
11103e54a169SMatthias Schwarzott 	.info = {
1111119bd82eSMatthias Schwarzott 		.name = "Silicon Labs ",
111294c17334SMatthias Schwarzott 		 /* For DVB-C */
111394c17334SMatthias Schwarzott 		.symbol_rate_min = 1000000,
111494c17334SMatthias Schwarzott 		.symbol_rate_max = 7200000,
111594c17334SMatthias Schwarzott 		/* For DVB-T */
1116f1b1eabfSMauro Carvalho Chehab 		.frequency_stepsize_hz = 166667,
11173e54a169SMatthias Schwarzott 		.caps = FE_CAN_FEC_1_2 |
11183e54a169SMatthias Schwarzott 			FE_CAN_FEC_2_3 |
11193e54a169SMatthias Schwarzott 			FE_CAN_FEC_3_4 |
11203e54a169SMatthias Schwarzott 			FE_CAN_FEC_5_6 |
11213e54a169SMatthias Schwarzott 			FE_CAN_FEC_7_8 |
11223e54a169SMatthias Schwarzott 			FE_CAN_FEC_AUTO |
11233e54a169SMatthias Schwarzott 			FE_CAN_QPSK |
11243e54a169SMatthias Schwarzott 			FE_CAN_QAM_16 |
11253e54a169SMatthias Schwarzott 			FE_CAN_QAM_32 |
11263e54a169SMatthias Schwarzott 			FE_CAN_QAM_64 |
11273e54a169SMatthias Schwarzott 			FE_CAN_QAM_128 |
11283e54a169SMatthias Schwarzott 			FE_CAN_QAM_256 |
11293e54a169SMatthias Schwarzott 			FE_CAN_GUARD_INTERVAL_AUTO |
11303e54a169SMatthias Schwarzott 			FE_CAN_HIERARCHY_AUTO |
11313e54a169SMatthias Schwarzott 			FE_CAN_MUTE_TS |
11323e54a169SMatthias Schwarzott 			FE_CAN_TRANSMISSION_MODE_AUTO |
11333e54a169SMatthias Schwarzott 			FE_CAN_RECOVER
11343e54a169SMatthias Schwarzott 	},
11353e54a169SMatthias Schwarzott 
11363e54a169SMatthias Schwarzott 	.get_tune_settings = si2165_get_tune_settings,
11373e54a169SMatthias Schwarzott 
11383e54a169SMatthias Schwarzott 	.init = si2165_init,
11393e54a169SMatthias Schwarzott 	.sleep = si2165_sleep,
11403e54a169SMatthias Schwarzott 
1141c1c49674SMatthias Schwarzott 	.set_frontend      = si2165_set_frontend,
11423e54a169SMatthias Schwarzott 	.read_status       = si2165_read_status,
11432e687a6dSMatthias Schwarzott 	.read_snr          = si2165_read_snr,
1144e9c7d19aSMatthias Schwarzott 	.read_ber          = si2165_read_ber,
11453e54a169SMatthias Schwarzott };
11463e54a169SMatthias Schwarzott 
si2165_probe(struct i2c_client * client)11473be25b9eSUwe Kleine-König static int si2165_probe(struct i2c_client *client)
11487cd785adSMatthias Schwarzott {
11497cd785adSMatthias Schwarzott 	struct si2165_state *state = NULL;
11507cd785adSMatthias Schwarzott 	struct si2165_platform_data *pdata = client->dev.platform_data;
11517cd785adSMatthias Schwarzott 	int n;
11527cd785adSMatthias Schwarzott 	int ret = 0;
11537cd785adSMatthias Schwarzott 	u8 val;
11547cd785adSMatthias Schwarzott 	char rev_char;
11557cd785adSMatthias Schwarzott 	const char *chip_name;
1156e3ea5e94SMatthias Schwarzott 	static const struct regmap_config regmap_config = {
1157e3ea5e94SMatthias Schwarzott 		.reg_bits = 16,
1158e3ea5e94SMatthias Schwarzott 		.val_bits = 8,
1159e3ea5e94SMatthias Schwarzott 		.max_register = 0x08ff,
1160e3ea5e94SMatthias Schwarzott 	};
11617cd785adSMatthias Schwarzott 
11627cd785adSMatthias Schwarzott 	/* allocate memory for the internal state */
11637dbbb4bfSMatthias Schwarzott 	state = kzalloc(sizeof(*state), GFP_KERNEL);
11647dbbb4bfSMatthias Schwarzott 	if (!state) {
11657cd785adSMatthias Schwarzott 		ret = -ENOMEM;
11667cd785adSMatthias Schwarzott 		goto error;
11677cd785adSMatthias Schwarzott 	}
11687cd785adSMatthias Schwarzott 
1169e3ea5e94SMatthias Schwarzott 	/* create regmap */
1170e3ea5e94SMatthias Schwarzott 	state->regmap = devm_regmap_init_i2c(client, &regmap_config);
1171e3ea5e94SMatthias Schwarzott 	if (IS_ERR(state->regmap)) {
1172e3ea5e94SMatthias Schwarzott 		ret = PTR_ERR(state->regmap);
1173e3ea5e94SMatthias Schwarzott 		goto error;
1174e3ea5e94SMatthias Schwarzott 	}
1175e3ea5e94SMatthias Schwarzott 
11767cd785adSMatthias Schwarzott 	/* setup the state */
11777cd785adSMatthias Schwarzott 	state->client = client;
11787cd785adSMatthias Schwarzott 	state->config.i2c_addr = client->addr;
11797cd785adSMatthias Schwarzott 	state->config.chip_mode = pdata->chip_mode;
11807dbbb4bfSMatthias Schwarzott 	state->config.ref_freq_hz = pdata->ref_freq_hz;
11817cd785adSMatthias Schwarzott 	state->config.inversion = pdata->inversion;
11827cd785adSMatthias Schwarzott 
11837dbbb4bfSMatthias Schwarzott 	if (state->config.ref_freq_hz < 4000000 ||
11847dbbb4bfSMatthias Schwarzott 	    state->config.ref_freq_hz > 27000000) {
118577f887cdSMatthias Schwarzott 		dev_err(&state->client->dev, "ref_freq of %d Hz not supported by this driver\n",
11867dbbb4bfSMatthias Schwarzott 			state->config.ref_freq_hz);
11877cd785adSMatthias Schwarzott 		ret = -EINVAL;
11887cd785adSMatthias Schwarzott 		goto error;
11897cd785adSMatthias Schwarzott 	}
11907cd785adSMatthias Schwarzott 
11917cd785adSMatthias Schwarzott 	/* create dvb_frontend */
11927cd785adSMatthias Schwarzott 	memcpy(&state->fe.ops, &si2165_ops,
11937cd785adSMatthias Schwarzott 	       sizeof(struct dvb_frontend_ops));
11947cd785adSMatthias Schwarzott 	state->fe.ops.release = NULL;
11957cd785adSMatthias Schwarzott 	state->fe.demodulator_priv = state;
11967cd785adSMatthias Schwarzott 	i2c_set_clientdata(client, state);
11977cd785adSMatthias Schwarzott 
11987cd785adSMatthias Schwarzott 	/* powerup */
1199814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_MODE, state->config.chip_mode);
12007cd785adSMatthias Schwarzott 	if (ret < 0)
12017cd785adSMatthias Schwarzott 		goto nodev_error;
12027cd785adSMatthias Schwarzott 
1203814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_CHIP_MODE, &val);
12047cd785adSMatthias Schwarzott 	if (ret < 0)
12057cd785adSMatthias Schwarzott 		goto nodev_error;
12067cd785adSMatthias Schwarzott 	if (val != state->config.chip_mode)
12077cd785adSMatthias Schwarzott 		goto nodev_error;
12087cd785adSMatthias Schwarzott 
1209814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REG_CHIP_REVCODE, &state->chip_revcode);
12107cd785adSMatthias Schwarzott 	if (ret < 0)
12117cd785adSMatthias Schwarzott 		goto nodev_error;
12127cd785adSMatthias Schwarzott 
1213814f86c9SMatthias Schwarzott 	ret = si2165_readreg8(state, REV_CHIP_TYPE, &state->chip_type);
12147cd785adSMatthias Schwarzott 	if (ret < 0)
12157cd785adSMatthias Schwarzott 		goto nodev_error;
12167cd785adSMatthias Schwarzott 
12177cd785adSMatthias Schwarzott 	/* powerdown */
1218814f86c9SMatthias Schwarzott 	ret = si2165_writereg8(state, REG_CHIP_MODE, SI2165_MODE_OFF);
12197cd785adSMatthias Schwarzott 	if (ret < 0)
12207cd785adSMatthias Schwarzott 		goto nodev_error;
12217cd785adSMatthias Schwarzott 
12227cd785adSMatthias Schwarzott 	if (state->chip_revcode < 26)
12237cd785adSMatthias Schwarzott 		rev_char = 'A' + state->chip_revcode;
12247cd785adSMatthias Schwarzott 	else
12257cd785adSMatthias Schwarzott 		rev_char = '?';
12267cd785adSMatthias Schwarzott 
12277cd785adSMatthias Schwarzott 	switch (state->chip_type) {
12287cd785adSMatthias Schwarzott 	case 0x06:
12297cd785adSMatthias Schwarzott 		chip_name = "Si2161";
12307cd785adSMatthias Schwarzott 		state->has_dvbt = true;
12317cd785adSMatthias Schwarzott 		break;
12327cd785adSMatthias Schwarzott 	case 0x07:
12337cd785adSMatthias Schwarzott 		chip_name = "Si2165";
12347cd785adSMatthias Schwarzott 		state->has_dvbt = true;
12357cd785adSMatthias Schwarzott 		state->has_dvbc = true;
12367cd785adSMatthias Schwarzott 		break;
12377cd785adSMatthias Schwarzott 	default:
123877f887cdSMatthias Schwarzott 		dev_err(&state->client->dev, "Unsupported Silicon Labs chip (type %d, rev %d)\n",
123977f887cdSMatthias Schwarzott 			state->chip_type, state->chip_revcode);
12407cd785adSMatthias Schwarzott 		goto nodev_error;
12417cd785adSMatthias Schwarzott 	}
12427cd785adSMatthias Schwarzott 
1243aa155449SMatthias Schwarzott 	dev_info(&state->client->dev,
124477f887cdSMatthias Schwarzott 		 "Detected Silicon Labs %s-%c (type %d, rev %d)\n",
124577f887cdSMatthias Schwarzott 		chip_name, rev_char, state->chip_type,
12467cd785adSMatthias Schwarzott 		state->chip_revcode);
12477cd785adSMatthias Schwarzott 
12487cd785adSMatthias Schwarzott 	strlcat(state->fe.ops.info.name, chip_name,
12497cd785adSMatthias Schwarzott 		sizeof(state->fe.ops.info.name));
12507cd785adSMatthias Schwarzott 
12517cd785adSMatthias Schwarzott 	n = 0;
12527cd785adSMatthias Schwarzott 	if (state->has_dvbt) {
12537cd785adSMatthias Schwarzott 		state->fe.ops.delsys[n++] = SYS_DVBT;
12547cd785adSMatthias Schwarzott 		strlcat(state->fe.ops.info.name, " DVB-T",
12557cd785adSMatthias Schwarzott 			sizeof(state->fe.ops.info.name));
12567cd785adSMatthias Schwarzott 	}
12577cd785adSMatthias Schwarzott 	if (state->has_dvbc) {
12587cd785adSMatthias Schwarzott 		state->fe.ops.delsys[n++] = SYS_DVBC_ANNEX_A;
12597cd785adSMatthias Schwarzott 		strlcat(state->fe.ops.info.name, " DVB-C",
12607cd785adSMatthias Schwarzott 			sizeof(state->fe.ops.info.name));
12617cd785adSMatthias Schwarzott 	}
12627cd785adSMatthias Schwarzott 
12637cd785adSMatthias Schwarzott 	/* return fe pointer */
12647cd785adSMatthias Schwarzott 	*pdata->fe = &state->fe;
12657cd785adSMatthias Schwarzott 
12667cd785adSMatthias Schwarzott 	return 0;
12677cd785adSMatthias Schwarzott 
12687cd785adSMatthias Schwarzott nodev_error:
12697cd785adSMatthias Schwarzott 	ret = -ENODEV;
12707cd785adSMatthias Schwarzott error:
12717cd785adSMatthias Schwarzott 	kfree(state);
12727cd785adSMatthias Schwarzott 	dev_dbg(&client->dev, "failed=%d\n", ret);
12737cd785adSMatthias Schwarzott 	return ret;
12747cd785adSMatthias Schwarzott }
12757cd785adSMatthias Schwarzott 
si2165_remove(struct i2c_client * client)1276ed5c2f5fSUwe Kleine-König static void si2165_remove(struct i2c_client *client)
12777cd785adSMatthias Schwarzott {
12787cd785adSMatthias Schwarzott 	struct si2165_state *state = i2c_get_clientdata(client);
12797cd785adSMatthias Schwarzott 
12807cd785adSMatthias Schwarzott 	dev_dbg(&client->dev, "\n");
12817cd785adSMatthias Schwarzott 
12827cd785adSMatthias Schwarzott 	kfree(state);
12837cd785adSMatthias Schwarzott }
12847cd785adSMatthias Schwarzott 
12857cd785adSMatthias Schwarzott static const struct i2c_device_id si2165_id_table[] = {
12867cd785adSMatthias Schwarzott 	{"si2165", 0},
12877cd785adSMatthias Schwarzott 	{}
12887cd785adSMatthias Schwarzott };
12897cd785adSMatthias Schwarzott MODULE_DEVICE_TABLE(i2c, si2165_id_table);
12907cd785adSMatthias Schwarzott 
12917cd785adSMatthias Schwarzott static struct i2c_driver si2165_driver = {
12927cd785adSMatthias Schwarzott 	.driver = {
12937cd785adSMatthias Schwarzott 		.name	= "si2165",
12947cd785adSMatthias Schwarzott 	},
1295aaeb31c0SUwe Kleine-König 	.probe		= si2165_probe,
12967cd785adSMatthias Schwarzott 	.remove		= si2165_remove,
12977cd785adSMatthias Schwarzott 	.id_table	= si2165_id_table,
12987cd785adSMatthias Schwarzott };
12997cd785adSMatthias Schwarzott 
13007cd785adSMatthias Schwarzott module_i2c_driver(si2165_driver);
13017cd785adSMatthias Schwarzott 
13023e54a169SMatthias Schwarzott MODULE_DESCRIPTION("Silicon Labs Si2165 DVB-C/-T Demodulator driver");
13033e54a169SMatthias Schwarzott MODULE_AUTHOR("Matthias Schwarzott <zzam@gentoo.org>");
13043e54a169SMatthias Schwarzott MODULE_LICENSE("GPL");
130555bea400SMatthias Schwarzott MODULE_FIRMWARE(SI2165_FIRMWARE_REV_D);
1306