xref: /linux/drivers/media/dvb-frontends/lgdt3306a.c (revision 831a91120a9399a061f0cb0a4562ecf7c83b3926)
1b63b36faSFred Richter /*
2b63b36faSFred Richter  *    Support for LGDT3306A - 8VSB/QAM-B
3b63b36faSFred Richter  *
4b63b36faSFred Richter  *    Copyright (C) 2013 Fred Richter <frichter@hauppauge.com>
5b63b36faSFred Richter  *    - driver structure based on lgdt3305.[ch] by Michael Krufky
6b63b36faSFred Richter  *    - code based on LG3306_V0.35 API by LG Electronics Inc.
7b63b36faSFred Richter  *
8b63b36faSFred Richter  *    This program is free software; you can redistribute it and/or modify
9b63b36faSFred Richter  *    it under the terms of the GNU General Public License as published by
10b63b36faSFred Richter  *    the Free Software Foundation; either version 2 of the License, or
11b63b36faSFred Richter  *    (at your option) any later version.
12b63b36faSFred Richter  *
13b63b36faSFred Richter  *    This program is distributed in the hope that it will be useful,
14b63b36faSFred Richter  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
15b63b36faSFred Richter  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16b63b36faSFred Richter  *    GNU General Public License for more details.
17b63b36faSFred Richter  *
18b63b36faSFred Richter  *    You should have received a copy of the GNU General Public License
19b63b36faSFred Richter  *    along with this program; if not, write to the Free Software
20b63b36faSFred Richter  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21b63b36faSFred Richter  *
22b63b36faSFred Richter  */
23b63b36faSFred Richter 
24b63b36faSFred Richter #include <asm/div64.h>
25b63b36faSFred Richter #include <linux/dvb/frontend.h>
26b63b36faSFred Richter #include "dvb_math.h"
27b63b36faSFred Richter #include "lgdt3306a.h"
28b63b36faSFred Richter 
29b63b36faSFred Richter 
30b63b36faSFred Richter static int debug;
31b63b36faSFred Richter module_param(debug, int, 0644);
32b63b36faSFred Richter MODULE_PARM_DESC(debug, "set debug level (info=1, reg=2 (or-able))");
33b63b36faSFred Richter 
34b63b36faSFred Richter #define DBG_INFO 1
35b63b36faSFred Richter #define DBG_REG  2
368e8cd34eSMichael Ira Krufky #define DBG_DUMP 4 /* FGR - comment out to remove dump code */
37b63b36faSFred Richter 
38b63b36faSFred Richter #define lg_printk(kern, fmt, arg...)					\
39b63b36faSFred Richter 	printk(kern "%s(): " fmt, __func__, ##arg)
40b63b36faSFred Richter 
41b63b36faSFred Richter #define lg_info(fmt, arg...)	printk(KERN_INFO "lgdt3306a: " fmt, ##arg)
42b63b36faSFred Richter #define lg_warn(fmt, arg...)	lg_printk(KERN_WARNING,       fmt, ##arg)
43b63b36faSFred Richter #define lg_err(fmt, arg...)	lg_printk(KERN_ERR,           fmt, ##arg)
44b63b36faSFred Richter #define lg_dbg(fmt, arg...) if (debug & DBG_INFO)			\
45b63b36faSFred Richter 				lg_printk(KERN_DEBUG,         fmt, ##arg)
46b63b36faSFred Richter #define lg_reg(fmt, arg...) if (debug & DBG_REG)			\
47b63b36faSFred Richter 				lg_printk(KERN_DEBUG,         fmt, ##arg)
48b63b36faSFred Richter 
49b63b36faSFred Richter #define lg_chkerr(ret)							\
50b63b36faSFred Richter ({									\
51b63b36faSFred Richter 	int __ret;							\
52b63b36faSFred Richter 	__ret = (ret < 0);						\
53b63b36faSFred Richter 	if (__ret)							\
54b63b36faSFred Richter 		lg_err("error %d on line %d\n",	ret, __LINE__);		\
55b63b36faSFred Richter 	__ret;								\
56b63b36faSFred Richter })
57b63b36faSFred Richter 
58b63b36faSFred Richter struct lgdt3306a_state {
59b63b36faSFred Richter 	struct i2c_adapter *i2c_adap;
60b63b36faSFred Richter 	const struct lgdt3306a_config *cfg;
61b63b36faSFred Richter 
62b63b36faSFred Richter 	struct dvb_frontend frontend;
63b63b36faSFred Richter 
64b63b36faSFred Richter 	fe_modulation_t current_modulation;
65b63b36faSFred Richter 	u32 current_frequency;
66b63b36faSFred Richter 	u32 snr;
67b63b36faSFred Richter };
68b63b36faSFred Richter 
69b63b36faSFred Richter /* -----------------------------------------------
70b63b36faSFred Richter  LG3306A Register Usage
71b63b36faSFred Richter    (LG does not really name the registers, so this code does not either)
72b63b36faSFred Richter  0000 -> 00FF Common control and status
73b63b36faSFred Richter  1000 -> 10FF Synchronizer control and status
74b63b36faSFred Richter  1F00 -> 1FFF Smart Antenna control and status
75b63b36faSFred Richter  2100 -> 21FF VSB Equalizer control and status
76b63b36faSFred Richter  2800 -> 28FF QAM Equalizer control and status
77b63b36faSFred Richter  3000 -> 30FF FEC control and status
78b63b36faSFred Richter  ---------------------------------------------- */
79b63b36faSFred Richter 
80f883d603SMichael Ira Krufky enum lgdt3306a_lock_status {
81b63b36faSFred Richter 	LG3306_UNLOCK       = 0x00,
82b63b36faSFred Richter 	LG3306_LOCK         = 0x01,
83b63b36faSFred Richter 	LG3306_UNKNOWN_LOCK = 0xFF
84f883d603SMichael Ira Krufky };
85b63b36faSFred Richter 
86f883d603SMichael Ira Krufky enum lgdt3306a_neverlock_status {
87b63b36faSFred Richter 	LG3306_NL_INIT    = 0x00,
88b63b36faSFred Richter 	LG3306_NL_PROCESS = 0x01,
89b63b36faSFred Richter 	LG3306_NL_LOCK    = 0x02,
90b63b36faSFred Richter 	LG3306_NL_FAIL    = 0x03,
91b63b36faSFred Richter 	LG3306_NL_UNKNOWN = 0xFF
92f883d603SMichael Ira Krufky };
93b63b36faSFred Richter 
94f883d603SMichael Ira Krufky enum lgdt3306a_modulation {
95b63b36faSFred Richter 	LG3306_VSB          = 0x00,
96b63b36faSFred Richter 	LG3306_QAM64        = 0x01,
97b63b36faSFred Richter 	LG3306_QAM256       = 0x02,
98b63b36faSFred Richter 	LG3306_UNKNOWN_MODE = 0xFF
99f883d603SMichael Ira Krufky };
100b63b36faSFred Richter 
101f883d603SMichael Ira Krufky enum lgdt3306a_lock_check {
102b63b36faSFred Richter 	LG3306_SYNC_LOCK,
103b63b36faSFred Richter 	LG3306_FEC_LOCK,
104b63b36faSFred Richter 	LG3306_TR_LOCK,
105b63b36faSFred Richter 	LG3306_AGC_LOCK,
106f883d603SMichael Ira Krufky };
107b63b36faSFred Richter 
108b63b36faSFred Richter 
109b63b36faSFred Richter #ifdef DBG_DUMP
110b63b36faSFred Richter static void lgdt3306a_DumpAllRegs(struct lgdt3306a_state *state);
111b63b36faSFred Richter static void lgdt3306a_DumpRegs(struct lgdt3306a_state *state);
112b63b36faSFred Richter #endif
113b63b36faSFred Richter 
114b63b36faSFred Richter 
115b63b36faSFred Richter static int lgdt3306a_write_reg(struct lgdt3306a_state *state, u16 reg, u8 val)
116b63b36faSFred Richter {
117b63b36faSFred Richter 	int ret;
118b63b36faSFred Richter 	u8 buf[] = { reg >> 8, reg & 0xff, val };
119b63b36faSFred Richter 	struct i2c_msg msg = {
120b63b36faSFred Richter 		.addr = state->cfg->i2c_addr, .flags = 0,
121b63b36faSFred Richter 		.buf = buf, .len = 3,
122b63b36faSFred Richter 	};
123b63b36faSFred Richter 
124b63b36faSFred Richter 	lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, val);
125b63b36faSFred Richter 
126b63b36faSFred Richter 	ret = i2c_transfer(state->i2c_adap, &msg, 1);
127b63b36faSFred Richter 
128b63b36faSFred Richter 	if (ret != 1) {
129b63b36faSFred Richter 		lg_err("error (addr %02x %02x <- %02x, err = %i)\n",
130b63b36faSFred Richter 		       msg.buf[0], msg.buf[1], msg.buf[2], ret);
131b63b36faSFred Richter 		if (ret < 0)
132b63b36faSFred Richter 			return ret;
133b63b36faSFred Richter 		else
134b63b36faSFred Richter 			return -EREMOTEIO;
135b63b36faSFred Richter 	}
136b63b36faSFred Richter 	return 0;
137b63b36faSFred Richter }
138b63b36faSFred Richter 
139b63b36faSFred Richter static int lgdt3306a_read_reg(struct lgdt3306a_state *state, u16 reg, u8 *val)
140b63b36faSFred Richter {
141b63b36faSFred Richter 	int ret;
142b63b36faSFred Richter 	u8 reg_buf[] = { reg >> 8, reg & 0xff };
143b63b36faSFred Richter 	struct i2c_msg msg[] = {
144b63b36faSFred Richter 		{ .addr = state->cfg->i2c_addr,
145b63b36faSFred Richter 		  .flags = 0, .buf = reg_buf, .len = 2 },
146b63b36faSFred Richter 		{ .addr = state->cfg->i2c_addr,
147b63b36faSFred Richter 		  .flags = I2C_M_RD, .buf = val, .len = 1 },
148b63b36faSFred Richter 	};
149b63b36faSFred Richter 
150b63b36faSFred Richter 	ret = i2c_transfer(state->i2c_adap, msg, 2);
151b63b36faSFred Richter 
152b63b36faSFred Richter 	if (ret != 2) {
153b63b36faSFred Richter 		lg_err("error (addr %02x reg %04x error (ret == %i)\n",
154b63b36faSFred Richter 		       state->cfg->i2c_addr, reg, ret);
155b63b36faSFred Richter 		if (ret < 0)
156b63b36faSFred Richter 			return ret;
157b63b36faSFred Richter 		else
158b63b36faSFred Richter 			return -EREMOTEIO;
159b63b36faSFred Richter 	}
160b63b36faSFred Richter 	lg_reg("reg: 0x%04x, val: 0x%02x\n", reg, *val);
161b63b36faSFred Richter 
162b63b36faSFred Richter 	return 0;
163b63b36faSFred Richter }
164b63b36faSFred Richter 
165b63b36faSFred Richter #define read_reg(state, reg)						\
166b63b36faSFred Richter ({									\
167b63b36faSFred Richter 	u8 __val;							\
168b63b36faSFred Richter 	int ret = lgdt3306a_read_reg(state, reg, &__val);		\
169b63b36faSFred Richter 	if (lg_chkerr(ret))						\
170b63b36faSFred Richter 		__val = 0;						\
171b63b36faSFred Richter 	__val;								\
172b63b36faSFred Richter })
173b63b36faSFred Richter 
174b63b36faSFred Richter static int lgdt3306a_set_reg_bit(struct lgdt3306a_state *state,
175b63b36faSFred Richter 				u16 reg, int bit, int onoff)
176b63b36faSFred Richter {
177b63b36faSFred Richter 	u8 val;
178b63b36faSFred Richter 	int ret;
179b63b36faSFred Richter 
180b63b36faSFred Richter 	lg_reg("reg: 0x%04x, bit: %d, level: %d\n", reg, bit, onoff);
181b63b36faSFred Richter 
182b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, reg, &val);
183b63b36faSFred Richter 	if (lg_chkerr(ret))
184b63b36faSFred Richter 		goto fail;
185b63b36faSFred Richter 
186b63b36faSFred Richter 	val &= ~(1 << bit);
187b63b36faSFred Richter 	val |= (onoff & 1) << bit;
188b63b36faSFred Richter 
189b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, reg, val);
190b63b36faSFred Richter 	lg_chkerr(ret);
191b63b36faSFred Richter fail:
192b63b36faSFred Richter 	return ret;
193b63b36faSFred Richter }
194b63b36faSFred Richter 
195b63b36faSFred Richter /* ------------------------------------------------------------------------ */
196b63b36faSFred Richter 
197b63b36faSFred Richter static int lgdt3306a_soft_reset(struct lgdt3306a_state *state)
198b63b36faSFred Richter {
199b63b36faSFred Richter 	int ret;
200b63b36faSFred Richter 
201b63b36faSFred Richter 	lg_dbg("\n");
202b63b36faSFred Richter 
203b63b36faSFred Richter 	ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 0);
204b63b36faSFred Richter 	if (lg_chkerr(ret))
205b63b36faSFred Richter 		goto fail;
206b63b36faSFred Richter 
207b63b36faSFred Richter 	msleep(20);
208b63b36faSFred Richter 	ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 1);
209b63b36faSFred Richter 	lg_chkerr(ret);
210b63b36faSFred Richter 
211b63b36faSFred Richter fail:
212b63b36faSFred Richter 	return ret;
213b63b36faSFred Richter }
214b63b36faSFred Richter 
215b63b36faSFred Richter static int lgdt3306a_mpeg_mode(struct lgdt3306a_state *state,
216b63b36faSFred Richter 				     enum lgdt3306a_mpeg_mode mode)
217b63b36faSFred Richter {
218b63b36faSFred Richter 	u8 val;
219b63b36faSFred Richter 	int ret;
220b63b36faSFred Richter 
221b63b36faSFred Richter 	lg_dbg("(%d)\n", mode);
2228e8cd34eSMichael Ira Krufky 	/* transport packet format */
2238e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0071, 7, mode == LGDT3306A_MPEG_PARALLEL?1:0); /* TPSENB=0x80 */
224b63b36faSFred Richter 	if (lg_chkerr(ret))
225b63b36faSFred Richter 		goto fail;
226b63b36faSFred Richter 
2278e8cd34eSMichael Ira Krufky 	/* start of packet signal duration */
2288e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0071, 6, 0); /* TPSSOPBITEN=0x40; 0=byte duration, 1=bit duration */
229b63b36faSFred Richter 	if (lg_chkerr(ret))
230b63b36faSFred Richter 		goto fail;
231b63b36faSFred Richter 
232b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0070, &val);
233b63b36faSFred Richter 	if (lg_chkerr(ret))
234b63b36faSFred Richter 		goto fail;
235b63b36faSFred Richter 
2368e8cd34eSMichael Ira Krufky 	val |= 0x10; /* TPCLKSUPB=0x10 */
237b63b36faSFred Richter 
238b63b36faSFred Richter 	if (mode == LGDT3306A_MPEG_PARALLEL)
239b63b36faSFred Richter 		val &= ~0x10;
240b63b36faSFred Richter 
241b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0070, val);
242b63b36faSFred Richter 	lg_chkerr(ret);
243b63b36faSFred Richter 
244b63b36faSFred Richter fail:
245b63b36faSFred Richter 	return ret;
246b63b36faSFred Richter }
247b63b36faSFred Richter 
248b63b36faSFred Richter static int lgdt3306a_mpeg_mode_polarity(struct lgdt3306a_state *state,
249b63b36faSFred Richter 				       enum lgdt3306a_tp_clock_edge edge,
250b63b36faSFred Richter 				       enum lgdt3306a_tp_valid_polarity valid)
251b63b36faSFred Richter {
252b63b36faSFred Richter 	u8 val;
253b63b36faSFred Richter 	int ret;
254b63b36faSFred Richter 
255b63b36faSFred Richter 	lg_dbg("edge=%d, valid=%d\n", edge, valid);
256b63b36faSFred Richter 
257b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0070, &val);
258b63b36faSFred Richter 	if (lg_chkerr(ret))
259b63b36faSFred Richter 		goto fail;
260b63b36faSFred Richter 
2618e8cd34eSMichael Ira Krufky 	val &= ~0x06; /* TPCLKPOL=0x04, TPVALPOL=0x02 */
262b63b36faSFred Richter 
263b63b36faSFred Richter 	if (edge == LGDT3306A_TPCLK_RISING_EDGE)
264b63b36faSFred Richter 		val |= 0x04;
265b63b36faSFred Richter 	if (valid == LGDT3306A_TP_VALID_HIGH)
266b63b36faSFred Richter 		val |= 0x02;
267b63b36faSFred Richter 
268b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0070, val);
269b63b36faSFred Richter 	lg_chkerr(ret);
270b63b36faSFred Richter 
271b63b36faSFred Richter fail:
272b63b36faSFred Richter 	return ret;
273b63b36faSFred Richter }
274b63b36faSFred Richter 
275b63b36faSFred Richter static int lgdt3306a_mpeg_tristate(struct lgdt3306a_state *state,
276b63b36faSFred Richter 				     int mode)
277b63b36faSFred Richter {
278b63b36faSFred Richter 	u8 val;
279b63b36faSFred Richter 	int ret;
280b63b36faSFred Richter 
281b63b36faSFred Richter 	lg_dbg("(%d)\n", mode);
282b63b36faSFred Richter 
283b63b36faSFred Richter 	if (mode) {
284b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x0070, &val);
285b63b36faSFred Richter 		if (lg_chkerr(ret))
286b63b36faSFred Richter 			goto fail;
2878e8cd34eSMichael Ira Krufky 		val &= ~0xA8; /* Tristate bus; TPOUTEN=0x80, TPCLKOUTEN=0x20, TPDATAOUTEN=0x08 */
288b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0070, val);
289b63b36faSFred Richter 		if (lg_chkerr(ret))
290b63b36faSFred Richter 			goto fail;
291b63b36faSFred Richter 
2928e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0003, 6, 1); /* AGCIFOUTENB=0x40; 1=Disable IFAGC pin */
293b63b36faSFred Richter 		if (lg_chkerr(ret))
294b63b36faSFred Richter 			goto fail;
295b63b36faSFred Richter 
296b63b36faSFred Richter 	} else {
2978e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0003, 6, 0); /* enable IFAGC pin */
298b63b36faSFred Richter 		if (lg_chkerr(ret))
299b63b36faSFred Richter 			goto fail;
300b63b36faSFred Richter 
301b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x0070, &val);
302b63b36faSFred Richter 		if (lg_chkerr(ret))
303b63b36faSFred Richter 			goto fail;
304b63b36faSFred Richter 
3058e8cd34eSMichael Ira Krufky 		val |= 0xA8; /* enable bus */
306b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0070, val);
307b63b36faSFred Richter 		if (lg_chkerr(ret))
308b63b36faSFred Richter 			goto fail;
309b63b36faSFred Richter 	}
310b63b36faSFred Richter 
311b63b36faSFred Richter fail:
312b63b36faSFred Richter 	return ret;
313b63b36faSFred Richter }
314b63b36faSFred Richter 
315b63b36faSFred Richter static int lgdt3306a_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
316b63b36faSFred Richter {
317b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
318b63b36faSFred Richter 
319b63b36faSFred Richter 	lg_dbg("acquire=%d\n", acquire);
320b63b36faSFred Richter 
321b63b36faSFred Richter 	return lgdt3306a_mpeg_tristate(state, acquire ? 0 : 1);
322b63b36faSFred Richter 
323b63b36faSFred Richter }
324b63b36faSFred Richter 
325b63b36faSFred Richter static int lgdt3306a_power(struct lgdt3306a_state *state,
326b63b36faSFred Richter 				     int mode)
327b63b36faSFred Richter {
328b63b36faSFred Richter 	int ret;
329b63b36faSFred Richter 
330b63b36faSFred Richter 	lg_dbg("(%d)\n", mode);
331b63b36faSFred Richter 
332b63b36faSFred Richter 	if (mode == 0) {
3338e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 0); /* into reset */
334b63b36faSFred Richter 		if (lg_chkerr(ret))
335b63b36faSFred Richter 			goto fail;
336b63b36faSFred Richter 
3378e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0000, 0, 0); /* power down */
338b63b36faSFred Richter 		if (lg_chkerr(ret))
339b63b36faSFred Richter 			goto fail;
340b63b36faSFred Richter 
341b63b36faSFred Richter 	} else {
3428e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0000, 7, 1); /* out of reset */
343b63b36faSFred Richter 		if (lg_chkerr(ret))
344b63b36faSFred Richter 			goto fail;
345b63b36faSFred Richter 
3468e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_reg_bit(state, 0x0000, 0, 1); /* power up */
347b63b36faSFred Richter 		if (lg_chkerr(ret))
348b63b36faSFred Richter 			goto fail;
349b63b36faSFred Richter 	}
350b63b36faSFred Richter 
351b63b36faSFred Richter #ifdef DBG_DUMP
352b63b36faSFred Richter 	lgdt3306a_DumpAllRegs(state);
353b63b36faSFred Richter #endif
354b63b36faSFred Richter fail:
355b63b36faSFred Richter 	return ret;
356b63b36faSFred Richter }
357b63b36faSFred Richter 
358b63b36faSFred Richter 
359b63b36faSFred Richter static int lgdt3306a_set_vsb(struct lgdt3306a_state *state)
360b63b36faSFred Richter {
361b63b36faSFred Richter 	u8 val;
362b63b36faSFred Richter 	int ret;
363b63b36faSFred Richter 
364b63b36faSFred Richter 	lg_dbg("\n");
365b63b36faSFred Richter 
3668e8cd34eSMichael Ira Krufky 	/* 0. Spectrum inversion detection manual; spectrum inverted */
367b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0002, &val);
3688e8cd34eSMichael Ira Krufky 	val &= 0xF7; /* SPECINVAUTO Off */
3698e8cd34eSMichael Ira Krufky 	val |= 0x04; /* SPECINV On */
370b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0002, val);
371b63b36faSFred Richter 	if (lg_chkerr(ret))
372b63b36faSFred Richter 		goto fail;
373b63b36faSFred Richter 
3748e8cd34eSMichael Ira Krufky 	/* 1. Selection of standard mode(0x08=QAM, 0x80=VSB) */
375b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0008, 0x80);
376b63b36faSFred Richter 	if (lg_chkerr(ret))
377b63b36faSFred Richter 		goto fail;
378b63b36faSFred Richter 
3798e8cd34eSMichael Ira Krufky 	/* 2. Bandwidth mode for VSB(6MHz) */
380b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0009, &val);
381b63b36faSFred Richter 	val &= 0xE3;
3828e8cd34eSMichael Ira Krufky 	val |= 0x0C; /* STDOPDETTMODE[2:0]=3 */
383b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0009, val);
384b63b36faSFred Richter 	if (lg_chkerr(ret))
385b63b36faSFred Richter 		goto fail;
386b63b36faSFred Richter 
3878e8cd34eSMichael Ira Krufky 	/* 3. QAM mode detection mode(None) */
388b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0009, &val);
3898e8cd34eSMichael Ira Krufky 	val &= 0xFC; /* STDOPDETCMODE[1:0]=0 */
390b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0009, val);
391b63b36faSFred Richter 	if (lg_chkerr(ret))
392b63b36faSFred Richter 		goto fail;
393b63b36faSFred Richter 
3948e8cd34eSMichael Ira Krufky 	/* 4. ADC sampling frequency rate(2x sampling) */
395b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x000D, &val);
3968e8cd34eSMichael Ira Krufky 	val &= 0xBF; /* SAMPLING4XFEN=0 */
397b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x000D, val);
398b63b36faSFred Richter 	if (lg_chkerr(ret))
399b63b36faSFred Richter 		goto fail;
400b63b36faSFred Richter 
4018e8cd34eSMichael Ira Krufky #if 0
4028e8cd34eSMichael Ira Krufky 	/* FGR - disable any AICC filtering, testing only */
4038e8cd34eSMichael Ira Krufky 
404b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0024, 0x00);
405b63b36faSFred Richter 	if (lg_chkerr(ret))
406b63b36faSFred Richter 		goto fail;
407b63b36faSFred Richter 
4088e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ0 NT N-1(Video rejection) */
409b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002E, 0x00);
410b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002F, 0x00);
411b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0030, 0x00);
412b63b36faSFred Richter 
4138e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ1 NT N-1(Audio rejection) */
414b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002B, 0x00);
415b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002C, 0x00);
416b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002D, 0x00);
417b63b36faSFred Richter 
4188e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ2 NT Co-Channel(Video rejection) */
419b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0028, 0x00);
420b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0029, 0x00);
421b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002A, 0x00);
422b63b36faSFred Richter 
4238e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ3 NT Co-Channel(Audio rejection) */
424b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0025, 0x00);
425b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0026, 0x00);
426b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0027, 0x00);
427b63b36faSFred Richter 
4288e8cd34eSMichael Ira Krufky #else
4298e8cd34eSMichael Ira Krufky 	/* FGR - this works well for HVR-1955,1975 */
4308e8cd34eSMichael Ira Krufky 
4318e8cd34eSMichael Ira Krufky 	/* 5. AICCOPMODE  NT N-1 Adj. */
432b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0024, 0x5A);
433b63b36faSFred Richter 	if (lg_chkerr(ret))
434b63b36faSFred Richter 		goto fail;
435b63b36faSFred Richter 
4368e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ0 NT N-1(Video rejection) */
437b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002E, 0x5A);
438b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002F, 0x00);
439b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0030, 0x00);
440b63b36faSFred Richter 
4418e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ1 NT N-1(Audio rejection) */
442b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002B, 0x36);
443b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002C, 0x00);
444b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002D, 0x00);
445b63b36faSFred Richter 
4468e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ2 NT Co-Channel(Video rejection) */
447b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0028, 0x2A);
448b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0029, 0x00);
449b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x002A, 0x00);
450b63b36faSFred Richter 
4518e8cd34eSMichael Ira Krufky 	/* AICCFIXFREQ3 NT Co-Channel(Audio rejection) */
452b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0025, 0x06);
453b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0026, 0x00);
454b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0027, 0x00);
455b63b36faSFred Richter #endif
456b63b36faSFred Richter 
457b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x001E, &val);
458b63b36faSFred Richter 	val &= 0x0F;
459b63b36faSFred Richter 	val |= 0xA0;
460b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x001E, val);
461b63b36faSFred Richter 
462b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0022, 0x08);
463b63b36faSFred Richter 
464b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0023, 0xFF);
465b63b36faSFred Richter 
466b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x211F, &val);
467b63b36faSFred Richter 	val &= 0xEF;
468b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x211F, val);
469b63b36faSFred Richter 
470b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2173, 0x01);
471b63b36faSFred Richter 
472b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x1061, &val);
473b63b36faSFred Richter 	val &= 0xF8;
474b63b36faSFred Richter 	val |= 0x04;
475b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x1061, val);
476b63b36faSFred Richter 
477b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x103D, &val);
478b63b36faSFred Richter 	val &= 0xCF;
479b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x103D, val);
480b63b36faSFred Richter 
481b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2122, 0x40);
482b63b36faSFred Richter 
483b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2141, &val);
484b63b36faSFred Richter 	val &= 0x3F;
485b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2141, val);
486b63b36faSFred Richter 
487b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2135, &val);
488b63b36faSFred Richter 	val &= 0x0F;
489b63b36faSFred Richter 	val |= 0x70;
490b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2135, val);
491b63b36faSFred Richter 
492b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0003, &val);
493b63b36faSFred Richter 	val &= 0xF7;
494b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0003, val);
495b63b36faSFred Richter 
496b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x001C, &val);
497b63b36faSFred Richter 	val &= 0x7F;
498b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x001C, val);
499b63b36faSFred Richter 
5008e8cd34eSMichael Ira Krufky 	/* 6. EQ step size */
501b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2179, &val);
502b63b36faSFred Richter 	val &= 0xF8;
503b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2179, val);
504b63b36faSFred Richter 
505b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x217A, &val);
506b63b36faSFred Richter 	val &= 0xF8;
507b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x217A, val);
508b63b36faSFred Richter 
5098e8cd34eSMichael Ira Krufky 	/* 7. Reset */
510b63b36faSFred Richter 	ret = lgdt3306a_soft_reset(state);
511b63b36faSFred Richter 	if (lg_chkerr(ret))
512b63b36faSFred Richter 		goto fail;
513b63b36faSFred Richter 
514b63b36faSFred Richter 	lg_dbg("complete\n");
515b63b36faSFred Richter fail:
516b63b36faSFred Richter 	return ret;
517b63b36faSFred Richter }
518b63b36faSFred Richter 
519b63b36faSFred Richter static int lgdt3306a_set_qam(struct lgdt3306a_state *state, int modulation)
520b63b36faSFred Richter {
521b63b36faSFred Richter 	u8 val;
522b63b36faSFred Richter 	int ret;
523b63b36faSFred Richter 
524b63b36faSFred Richter 	lg_dbg("modulation=%d\n", modulation);
525b63b36faSFred Richter 
5268e8cd34eSMichael Ira Krufky 	/* 1. Selection of standard mode(0x08=QAM, 0x80=VSB) */
527b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0008, 0x08);
528b63b36faSFred Richter 	if (lg_chkerr(ret))
529b63b36faSFred Richter 		goto fail;
530b63b36faSFred Richter 
5318e8cd34eSMichael Ira Krufky 	/* 1a. Spectrum inversion detection to Auto */
532b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0002, &val);
5338e8cd34eSMichael Ira Krufky 	val &= 0xFB; /* SPECINV Off */
5348e8cd34eSMichael Ira Krufky 	val |= 0x08; /* SPECINVAUTO On */
535b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0002, val);
536b63b36faSFred Richter 	if (lg_chkerr(ret))
537b63b36faSFred Richter 		goto fail;
538b63b36faSFred Richter 
5398e8cd34eSMichael Ira Krufky 	/* 2. Bandwidth mode for QAM */
540b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0009, &val);
5418e8cd34eSMichael Ira Krufky 	val &= 0xE3; /* STDOPDETTMODE[2:0]=0 VSB Off */
542b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0009, val);
543b63b36faSFred Richter 	if (lg_chkerr(ret))
544b63b36faSFred Richter 		goto fail;
545b63b36faSFred Richter 
5468e8cd34eSMichael Ira Krufky 	/* 3. : 64QAM/256QAM detection(manual, auto) */
547b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0009, &val);
548b63b36faSFred Richter 	val &= 0xFC;
5498e8cd34eSMichael Ira Krufky 	val |= 0x02; /* STDOPDETCMODE[1:0]=1=Manual 2=Auto */
550b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0009, val);
551b63b36faSFred Richter 	if (lg_chkerr(ret))
552b63b36faSFred Richter 		goto fail;
553b63b36faSFred Richter 
5548e8cd34eSMichael Ira Krufky 	/* 3a. : 64QAM/256QAM selection for manual */
555b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x101a, &val);
556b63b36faSFred Richter 	val &= 0xF8;
5578e8cd34eSMichael Ira Krufky 	if (modulation == QAM_64)
5588e8cd34eSMichael Ira Krufky 		val |= 0x02; /* QMDQMODE[2:0]=2=QAM64 */
5598e8cd34eSMichael Ira Krufky 	else
5608e8cd34eSMichael Ira Krufky 		val |= 0x04; /* QMDQMODE[2:0]=4=QAM256 */
5618e8cd34eSMichael Ira Krufky 
562b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x101a, val);
563b63b36faSFred Richter 	if (lg_chkerr(ret))
564b63b36faSFred Richter 		goto fail;
565b63b36faSFred Richter 
5668e8cd34eSMichael Ira Krufky 	/* 4. ADC sampling frequency rate(4x sampling) */
567b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x000D, &val);
568b63b36faSFred Richter 	val &= 0xBF;
5698e8cd34eSMichael Ira Krufky 	val |= 0x40; /* SAMPLING4XFEN=1 */
570b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x000D, val);
571b63b36faSFred Richter 	if (lg_chkerr(ret))
572b63b36faSFred Richter 		goto fail;
573b63b36faSFred Richter 
5748e8cd34eSMichael Ira Krufky 	/* 5. No AICC operation in QAM mode */
575b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0024, &val);
576b63b36faSFred Richter 	val &= 0x00;
577b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0024, val);
578b63b36faSFred Richter 	if (lg_chkerr(ret))
579b63b36faSFred Richter 		goto fail;
580b63b36faSFred Richter 
5818e8cd34eSMichael Ira Krufky 	/* 6. Reset */
582b63b36faSFred Richter 	ret = lgdt3306a_soft_reset(state);
583b63b36faSFred Richter 	if (lg_chkerr(ret))
584b63b36faSFred Richter 		goto fail;
585b63b36faSFred Richter 
586b63b36faSFred Richter 	lg_dbg("complete\n");
587b63b36faSFred Richter fail:
588b63b36faSFred Richter 	return ret;
589b63b36faSFred Richter }
590b63b36faSFred Richter 
591b63b36faSFred Richter static int lgdt3306a_set_modulation(struct lgdt3306a_state *state,
592b63b36faSFred Richter 				   struct dtv_frontend_properties *p)
593b63b36faSFred Richter {
594b63b36faSFred Richter 	int ret;
595b63b36faSFred Richter 
596b63b36faSFred Richter 	lg_dbg("\n");
597b63b36faSFred Richter 
598b63b36faSFred Richter 	switch (p->modulation) {
599b63b36faSFred Richter 	case VSB_8:
600b63b36faSFred Richter 		ret = lgdt3306a_set_vsb(state);
601b63b36faSFred Richter 		break;
602b63b36faSFred Richter 	case QAM_64:
603b63b36faSFred Richter 		ret = lgdt3306a_set_qam(state, QAM_64);
604b63b36faSFred Richter 		break;
605b63b36faSFred Richter 	case QAM_256:
606b63b36faSFred Richter 		ret = lgdt3306a_set_qam(state, QAM_256);
607b63b36faSFred Richter 		break;
608b63b36faSFred Richter 	default:
609b63b36faSFred Richter 		return -EINVAL;
610b63b36faSFred Richter 	}
611b63b36faSFred Richter 	if (lg_chkerr(ret))
612b63b36faSFred Richter 		goto fail;
613b63b36faSFred Richter 
614b63b36faSFred Richter 	state->current_modulation = p->modulation;
615b63b36faSFred Richter 
616b63b36faSFred Richter fail:
617b63b36faSFred Richter 	return ret;
618b63b36faSFred Richter }
619b63b36faSFred Richter 
620b63b36faSFred Richter /* ------------------------------------------------------------------------ */
621b63b36faSFred Richter 
622b63b36faSFred Richter static int lgdt3306a_agc_setup(struct lgdt3306a_state *state,
623b63b36faSFred Richter 			      struct dtv_frontend_properties *p)
624b63b36faSFred Richter {
6258e8cd34eSMichael Ira Krufky 	/* TODO: anything we want to do here??? */
626b63b36faSFred Richter 	lg_dbg("\n");
627b63b36faSFred Richter 
628b63b36faSFred Richter 	switch (p->modulation) {
629b63b36faSFred Richter 	case VSB_8:
630b63b36faSFred Richter 		break;
631b63b36faSFred Richter 	case QAM_64:
632b63b36faSFred Richter 	case QAM_256:
633b63b36faSFred Richter 		break;
634b63b36faSFred Richter 	default:
635b63b36faSFred Richter 		return -EINVAL;
636b63b36faSFred Richter 	}
637b63b36faSFred Richter 	return 0;
638b63b36faSFred Richter }
639b63b36faSFred Richter 
640b63b36faSFred Richter /* ------------------------------------------------------------------------ */
641b63b36faSFred Richter 
642b63b36faSFred Richter static int lgdt3306a_set_inversion(struct lgdt3306a_state *state,
643b63b36faSFred Richter 				       int inversion)
644b63b36faSFred Richter {
645b63b36faSFred Richter 	int ret;
646b63b36faSFred Richter 
647b63b36faSFred Richter 	lg_dbg("(%d)\n", inversion);
648b63b36faSFred Richter 
649b63b36faSFred Richter 	ret = lgdt3306a_set_reg_bit(state, 0x0002, 2, inversion ? 1 : 0);
650b63b36faSFred Richter 	return ret;
651b63b36faSFred Richter }
652b63b36faSFred Richter 
653b63b36faSFred Richter static int lgdt3306a_set_inversion_auto(struct lgdt3306a_state *state,
654b63b36faSFred Richter 				       int enabled)
655b63b36faSFred Richter {
656b63b36faSFred Richter 	int ret;
657b63b36faSFred Richter 
658b63b36faSFred Richter 	lg_dbg("(%d)\n", enabled);
659b63b36faSFred Richter 
6608e8cd34eSMichael Ira Krufky 	/* 0=Manual 1=Auto(QAM only) */
6618e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0002, 3, enabled);/* SPECINVAUTO=0x04 */
662b63b36faSFred Richter 	return ret;
663b63b36faSFred Richter }
664b63b36faSFred Richter 
665b63b36faSFred Richter static int lgdt3306a_spectral_inversion(struct lgdt3306a_state *state,
666b63b36faSFred Richter 				       struct dtv_frontend_properties *p,
667b63b36faSFred Richter 				       int inversion)
668b63b36faSFred Richter {
669b63b36faSFred Richter 	int ret = 0;
670b63b36faSFred Richter 
671b63b36faSFred Richter 	lg_dbg("(%d)\n", inversion);
6728e8cd34eSMichael Ira Krufky #if 0
6738e8cd34eSMichael Ira Krufky /* FGR - spectral_inversion defaults already set for VSB and QAM; can enable later if desired */
674b63b36faSFred Richter 
675b63b36faSFred Richter 	ret = lgdt3306a_set_inversion(state, inversion);
676b63b36faSFred Richter 
677b63b36faSFred Richter 	switch (p->modulation) {
678b63b36faSFred Richter 	case VSB_8:
6798e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_inversion_auto(state, 0); /* Manual only for VSB */
680b63b36faSFred Richter 		break;
681b63b36faSFred Richter 	case QAM_64:
682b63b36faSFred Richter 	case QAM_256:
6838e8cd34eSMichael Ira Krufky 		ret = lgdt3306a_set_inversion_auto(state, 1); /* Auto ok for QAM */
684b63b36faSFred Richter 		break;
685b63b36faSFred Richter 	default:
686b63b36faSFred Richter 		ret = -EINVAL;
687b63b36faSFred Richter 	}
688b63b36faSFred Richter #endif
689b63b36faSFred Richter 	return ret;
690b63b36faSFred Richter }
691b63b36faSFred Richter 
692b63b36faSFred Richter static int lgdt3306a_set_if(struct lgdt3306a_state *state,
693b63b36faSFred Richter 			   struct dtv_frontend_properties *p)
694b63b36faSFred Richter {
695b63b36faSFred Richter 	int ret;
696b63b36faSFred Richter 	u16 if_freq_khz;
697b63b36faSFred Richter 	u8 nco1, nco2;
698b63b36faSFred Richter 
699b63b36faSFred Richter 	switch (p->modulation) {
700b63b36faSFred Richter 	case VSB_8:
701b63b36faSFred Richter 		if_freq_khz = state->cfg->vsb_if_khz;
702b63b36faSFred Richter 		break;
703b63b36faSFred Richter 	case QAM_64:
704b63b36faSFred Richter 	case QAM_256:
705b63b36faSFred Richter 		if_freq_khz = state->cfg->qam_if_khz;
706b63b36faSFred Richter 		break;
707b63b36faSFred Richter 	default:
708b63b36faSFred Richter 		return -EINVAL;
709b63b36faSFred Richter 	}
710b63b36faSFred Richter 
711b63b36faSFred Richter 	switch (if_freq_khz) {
712b63b36faSFred Richter 	default:
713b63b36faSFred Richter 	    lg_warn("IF=%d KHz is not supportted, 3250 assumed\n", if_freq_khz);
7148e8cd34eSMichael Ira Krufky 		/* fallthrough */
7158e8cd34eSMichael Ira Krufky 	case 3250:  /* 3.25Mhz */
716b63b36faSFred Richter 		nco1 = 0x34;
717b63b36faSFred Richter 		nco2 = 0x00;
718b63b36faSFred Richter 		break;
7198e8cd34eSMichael Ira Krufky 	case 3500:  /* 3.50Mhz */
720b63b36faSFred Richter 		nco1 = 0x38;
721b63b36faSFred Richter 		nco2 = 0x00;
722b63b36faSFred Richter 		break;
7238e8cd34eSMichael Ira Krufky 	case 4000:  /* 4.00Mhz */
724b63b36faSFred Richter 		nco1 = 0x40;
725b63b36faSFred Richter 		nco2 = 0x00;
726b63b36faSFred Richter 		break;
7278e8cd34eSMichael Ira Krufky 	case 5000:  /* 5.00Mhz */
728b63b36faSFred Richter 		nco1 = 0x50;
729b63b36faSFred Richter 		nco2 = 0x00;
730b63b36faSFred Richter 		break;
7318e8cd34eSMichael Ira Krufky 	case 5380: /* 5.38Mhz */
732b63b36faSFred Richter 		nco1 = 0x56;
733b63b36faSFred Richter 		nco2 = 0x14;
734b63b36faSFred Richter 		break;
735b63b36faSFred Richter 	}
736b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0010, nco1);
737b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0011, nco2);
738b63b36faSFred Richter 
739b63b36faSFred Richter 	lg_dbg("if_freq=%d KHz->[%04x]\n", if_freq_khz, nco1<<8 | nco2);
740b63b36faSFred Richter 
741b63b36faSFred Richter 	return 0;
742b63b36faSFred Richter }
743b63b36faSFred Richter 
744b63b36faSFred Richter /* ------------------------------------------------------------------------ */
745b63b36faSFred Richter 
746b63b36faSFred Richter static int lgdt3306a_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
747b63b36faSFred Richter {
748b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
749b63b36faSFred Richter 
750b63b36faSFred Richter 	if (state->cfg->deny_i2c_rptr) {
751b63b36faSFred Richter 		lg_dbg("deny_i2c_rptr=%d\n", state->cfg->deny_i2c_rptr);
752b63b36faSFred Richter 		return 0;
753b63b36faSFred Richter 	}
754b63b36faSFred Richter 	lg_dbg("(%d)\n", enable);
755b63b36faSFred Richter 
7568e8cd34eSMichael Ira Krufky 	return lgdt3306a_set_reg_bit(state, 0x0002, 7, enable ? 0 : 1); /* NI2CRPTEN=0x80 */
757b63b36faSFred Richter }
758b63b36faSFred Richter 
759b63b36faSFred Richter static int lgdt3306a_sleep(struct lgdt3306a_state *state)
760b63b36faSFred Richter {
761b63b36faSFred Richter 	int ret;
762b63b36faSFred Richter 
763b63b36faSFred Richter 	lg_dbg("\n");
7648e8cd34eSMichael Ira Krufky 	state->current_frequency = -1; /* force re-tune, when we wake */
765b63b36faSFred Richter 
7668e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_mpeg_tristate(state, 1); /* disable data bus */
767b63b36faSFred Richter 	if (lg_chkerr(ret))
768b63b36faSFred Richter 		goto fail;
769b63b36faSFred Richter 
7708e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_power(state, 0); /* power down */
771b63b36faSFred Richter 	lg_chkerr(ret);
772b63b36faSFred Richter 
773b63b36faSFred Richter fail:
774b63b36faSFred Richter 	return 0;
775b63b36faSFred Richter }
776b63b36faSFred Richter 
777b63b36faSFred Richter static int lgdt3306a_fe_sleep(struct dvb_frontend *fe)
778b63b36faSFred Richter {
779b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
780b63b36faSFred Richter 
781b63b36faSFred Richter 	return lgdt3306a_sleep(state);
782b63b36faSFred Richter }
783b63b36faSFred Richter 
784b63b36faSFred Richter static int lgdt3306a_init(struct dvb_frontend *fe)
785b63b36faSFred Richter {
786b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
787b63b36faSFred Richter 	u8 val;
788b63b36faSFred Richter 	int ret;
789b63b36faSFred Richter 
790b63b36faSFred Richter 	lg_dbg("\n");
791b63b36faSFred Richter 
7928e8cd34eSMichael Ira Krufky 	/* 1. Normal operation mode */
7938e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0001, 0, 1); /* SIMFASTENB=0x01 */
794b63b36faSFred Richter 	if (lg_chkerr(ret))
795b63b36faSFred Richter 		goto fail;
796b63b36faSFred Richter 
7978e8cd34eSMichael Ira Krufky 	/* 2. Spectrum inversion auto detection (Not valid for VSB) */
798b63b36faSFred Richter 	ret = lgdt3306a_set_inversion_auto(state, 0);
799b63b36faSFred Richter 	if (lg_chkerr(ret))
800b63b36faSFred Richter 		goto fail;
801b63b36faSFred Richter 
8028e8cd34eSMichael Ira Krufky 	/* 3. Spectrum inversion(According to the tuner configuration) */
803b63b36faSFred Richter 	ret = lgdt3306a_set_inversion(state, 1);
804b63b36faSFred Richter 	if (lg_chkerr(ret))
805b63b36faSFred Richter 		goto fail;
806b63b36faSFred Richter 
8078e8cd34eSMichael Ira Krufky 	/* 4. Peak-to-peak voltage of ADC input signal */
8088e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0004, 7, 1); /* ADCSEL1V=0x80=1Vpp; 0x00=2Vpp */
809b63b36faSFred Richter 	if (lg_chkerr(ret))
810b63b36faSFred Richter 		goto fail;
811b63b36faSFred Richter 
8128e8cd34eSMichael Ira Krufky 	/* 5. ADC output data capture clock phase */
8138e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0004, 2, 0); /* 0=same phase as ADC clock */
814b63b36faSFred Richter 	if (lg_chkerr(ret))
815b63b36faSFred Richter 		goto fail;
816b63b36faSFred Richter 
8178e8cd34eSMichael Ira Krufky 	/* 5a. ADC sampling clock source */
8188e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0004, 3, 0); /* ADCCLKPLLSEL=0x08; 0=use ext clock, not PLL */
819b63b36faSFred Richter 	if (lg_chkerr(ret))
820b63b36faSFred Richter 		goto fail;
821b63b36faSFred Richter 
8228e8cd34eSMichael Ira Krufky 	/* 6. Automatic PLL set */
8238e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_set_reg_bit(state, 0x0005, 6, 0); /* PLLSETAUTO=0x40; 0=off */
824b63b36faSFred Richter 	if (lg_chkerr(ret))
825b63b36faSFred Richter 		goto fail;
826b63b36faSFred Richter 
8278e8cd34eSMichael Ira Krufky 	if (state->cfg->xtalMHz == 24) {	/* 24MHz */
8288e8cd34eSMichael Ira Krufky 		/* 7. Frequency for PLL output(0x2564 for 192MHz for 24MHz) */
829b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x0005, &val);
830b63b36faSFred Richter 		if (lg_chkerr(ret))
831b63b36faSFred Richter 			goto fail;
832b63b36faSFred Richter 		val &= 0xC0;
833b63b36faSFred Richter 		val |= 0x25;
834b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0005, val);
835b63b36faSFred Richter 		if (lg_chkerr(ret))
836b63b36faSFred Richter 			goto fail;
837b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0006, 0x64);
838b63b36faSFred Richter 		if (lg_chkerr(ret))
839b63b36faSFred Richter 			goto fail;
840b63b36faSFred Richter 
8418e8cd34eSMichael Ira Krufky 		/* 8. ADC sampling frequency(0x180000 for 24MHz sampling) */
842b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x000D, &val);
843b63b36faSFred Richter 		if (lg_chkerr(ret))
844b63b36faSFred Richter 			goto fail;
845b63b36faSFred Richter 		val &= 0xC0;
846b63b36faSFred Richter 		val |= 0x18;
847b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x000D, val);
848b63b36faSFred Richter 		if (lg_chkerr(ret))
849b63b36faSFred Richter 			goto fail;
850b63b36faSFred Richter 
8518e8cd34eSMichael Ira Krufky 	} else if (state->cfg->xtalMHz == 25) { /* 25MHz */
8528e8cd34eSMichael Ira Krufky 		/* 7. Frequency for PLL output */
853b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x0005, &val);
854b63b36faSFred Richter 		if (lg_chkerr(ret))
855b63b36faSFred Richter 			goto fail;
856b63b36faSFred Richter 		val &= 0xC0;
857b63b36faSFred Richter 		val |= 0x25;
858b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0005, val);
859b63b36faSFred Richter 		if (lg_chkerr(ret))
860b63b36faSFred Richter 			goto fail;
861b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x0006, 0x64);
862b63b36faSFred Richter 		if (lg_chkerr(ret))
863b63b36faSFred Richter 			goto fail;
864b63b36faSFred Richter 
8658e8cd34eSMichael Ira Krufky 		/* 8. ADC sampling frequency(0x190000 for 25MHz sampling) */
866b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x000D, &val);
867b63b36faSFred Richter 		if (lg_chkerr(ret))
868b63b36faSFred Richter 			goto fail;
869b63b36faSFred Richter 		val &= 0xC0;
870b63b36faSFred Richter 		val |= 0x19;
871b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x000D, val);
872b63b36faSFred Richter 		if (lg_chkerr(ret))
873b63b36faSFred Richter 			goto fail;
874b63b36faSFred Richter 	} else {
875b63b36faSFred Richter 		lg_err("Bad xtalMHz=%d\n", state->cfg->xtalMHz);
876b63b36faSFred Richter 	}
8778e8cd34eSMichael Ira Krufky #if 0
8788e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_write_reg(state, 0x000E, 0x00);
8798e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_write_reg(state, 0x000F, 0x00);
8808e8cd34eSMichael Ira Krufky #endif
881b63b36faSFred Richter 
8828e8cd34eSMichael Ira Krufky 	/* 9. Center frequency of input signal of ADC */
8838e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_write_reg(state, 0x0010, 0x34); /* 3.25MHz */
884b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0011, 0x00);
885b63b36faSFred Richter 
8868e8cd34eSMichael Ira Krufky 	/* 10. Fixed gain error value */
8878e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_write_reg(state, 0x0014, 0); /* gain error=0 */
888b63b36faSFred Richter 
8898e8cd34eSMichael Ira Krufky 	/* 10a. VSB TR BW gear shift initial step */
890b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x103C, &val);
891b63b36faSFred Richter 	val &= 0x0F;
8928e8cd34eSMichael Ira Krufky 	val |= 0x20; /* SAMGSAUTOSTL_V[3:0] = 2 */
893b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x103C, val);
894b63b36faSFred Richter 
8958e8cd34eSMichael Ira Krufky 	/* 10b. Timing offset calibration in low temperature for VSB */
896b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x103D, &val);
897b63b36faSFred Richter 	val &= 0xFC;
898b63b36faSFred Richter 	val |= 0x03;
899b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x103D, val);
900b63b36faSFred Richter 
9018e8cd34eSMichael Ira Krufky 	/* 10c. Timing offset calibration in low temperature for QAM */
902b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x1036, &val);
903b63b36faSFred Richter 	val &= 0xF0;
904b63b36faSFred Richter 	val |= 0x0C;
905b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x1036, val);
906b63b36faSFred Richter 
9078e8cd34eSMichael Ira Krufky 	/* 11. Using the imaginary part of CIR in CIR loading */
908b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x211F, &val);
9098e8cd34eSMichael Ira Krufky 	val &= 0xEF; /* do not use imaginary of CIR */
910b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x211F, val);
911b63b36faSFred Richter 
9128e8cd34eSMichael Ira Krufky 	/* 12. Control of no signal detector function */
913b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2849, &val);
9148e8cd34eSMichael Ira Krufky 	val &= 0xEF; /* NOUSENOSIGDET=0, enable no signal detector */
915b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x2849, val);
916b63b36faSFred Richter 
9178e8cd34eSMichael Ira Krufky 	/* FGR - put demod in some known mode */
918b63b36faSFred Richter 	ret = lgdt3306a_set_vsb(state);
919b63b36faSFred Richter 
9208e8cd34eSMichael Ira Krufky 	/* 13. TP stream format */
921b63b36faSFred Richter 	ret = lgdt3306a_mpeg_mode(state, state->cfg->mpeg_mode);
922b63b36faSFred Richter 
9238e8cd34eSMichael Ira Krufky 	/* 14. disable output buses */
924b63b36faSFred Richter 	ret = lgdt3306a_mpeg_tristate(state, 1);
925b63b36faSFred Richter 
9268e8cd34eSMichael Ira Krufky 	/* 15. Sleep (in reset) */
927b63b36faSFred Richter 	ret = lgdt3306a_sleep(state);
928b63b36faSFred Richter 	lg_chkerr(ret);
929b63b36faSFred Richter 
930b63b36faSFred Richter fail:
931b63b36faSFred Richter 	return ret;
932b63b36faSFred Richter }
933b63b36faSFred Richter 
934b63b36faSFred Richter static int lgdt3306a_set_parameters(struct dvb_frontend *fe)
935b63b36faSFred Richter {
936b63b36faSFred Richter 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
937b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
938b63b36faSFred Richter 	int ret;
939b63b36faSFred Richter 
940b63b36faSFred Richter 	lg_dbg("(%d, %d)\n", p->frequency, p->modulation);
941b63b36faSFred Richter 
942b63b36faSFred Richter 	if (state->current_frequency  == p->frequency &&
943b63b36faSFred Richter 	   state->current_modulation == p->modulation) {
944b63b36faSFred Richter 		lg_dbg(" (already set, skipping ...)\n");
945b63b36faSFred Richter 		return 0;
946b63b36faSFred Richter 	}
947b63b36faSFred Richter 	state->current_frequency = -1;
948b63b36faSFred Richter 	state->current_modulation = -1;
949b63b36faSFred Richter 
9508e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_power(state, 1); /* power up */
951b63b36faSFred Richter 	if (lg_chkerr(ret))
952b63b36faSFred Richter 		goto fail;
953b63b36faSFred Richter 
954b63b36faSFred Richter 	if (fe->ops.tuner_ops.set_params) {
955b63b36faSFred Richter 		ret = fe->ops.tuner_ops.set_params(fe);
956b63b36faSFred Richter 		if (fe->ops.i2c_gate_ctrl)
957b63b36faSFred Richter 			fe->ops.i2c_gate_ctrl(fe, 0);
9588e8cd34eSMichael Ira Krufky #if 0
9598e8cd34eSMichael Ira Krufky 		if (lg_chkerr(ret))
9608e8cd34eSMichael Ira Krufky 			goto fail;
9618e8cd34eSMichael Ira Krufky 		state->current_frequency = p->frequency;
9628e8cd34eSMichael Ira Krufky #endif
963b63b36faSFred Richter 	}
964b63b36faSFred Richter 
965b63b36faSFred Richter 	ret = lgdt3306a_set_modulation(state, p);
966b63b36faSFred Richter 	if (lg_chkerr(ret))
967b63b36faSFred Richter 		goto fail;
968b63b36faSFred Richter 
969b63b36faSFred Richter 	ret = lgdt3306a_agc_setup(state, p);
970b63b36faSFred Richter 	if (lg_chkerr(ret))
971b63b36faSFred Richter 		goto fail;
972b63b36faSFred Richter 
973b63b36faSFred Richter 	ret = lgdt3306a_set_if(state, p);
974b63b36faSFred Richter 	if (lg_chkerr(ret))
975b63b36faSFred Richter 		goto fail;
976b63b36faSFred Richter 
977b63b36faSFred Richter 	ret = lgdt3306a_spectral_inversion(state, p,
978b63b36faSFred Richter 					  state->cfg->spectral_inversion ? 1 : 0);
979b63b36faSFred Richter 	if (lg_chkerr(ret))
980b63b36faSFred Richter 		goto fail;
981b63b36faSFred Richter 
982b63b36faSFred Richter 	ret = lgdt3306a_mpeg_mode(state, state->cfg->mpeg_mode);
983b63b36faSFred Richter 	if (lg_chkerr(ret))
984b63b36faSFred Richter 		goto fail;
985b63b36faSFred Richter 
986b63b36faSFred Richter 	ret = lgdt3306a_mpeg_mode_polarity(state,
987b63b36faSFred Richter 					  state->cfg->tpclk_edge,
988b63b36faSFred Richter 					  state->cfg->tpvalid_polarity);
989b63b36faSFred Richter 	if (lg_chkerr(ret))
990b63b36faSFred Richter 		goto fail;
991b63b36faSFred Richter 
9928e8cd34eSMichael Ira Krufky 	ret = lgdt3306a_mpeg_tristate(state, 0); /* enable data bus */
993b63b36faSFred Richter 	if (lg_chkerr(ret))
994b63b36faSFred Richter 		goto fail;
995b63b36faSFred Richter 
996b63b36faSFred Richter 	ret = lgdt3306a_soft_reset(state);
997b63b36faSFred Richter 	if (lg_chkerr(ret))
998b63b36faSFred Richter 		goto fail;
999b63b36faSFred Richter 
1000b63b36faSFred Richter #ifdef DBG_DUMP
1001b63b36faSFred Richter 	lgdt3306a_DumpAllRegs(state);
1002b63b36faSFred Richter #endif
1003b63b36faSFred Richter 	state->current_frequency = p->frequency;
1004b63b36faSFred Richter fail:
1005b63b36faSFred Richter 	return ret;
1006b63b36faSFred Richter }
1007b63b36faSFred Richter 
1008b63b36faSFred Richter static int lgdt3306a_get_frontend(struct dvb_frontend *fe)
1009b63b36faSFred Richter {
1010b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1011b63b36faSFred Richter 	struct dtv_frontend_properties *p = &fe->dtv_property_cache;
1012b63b36faSFred Richter 
1013b63b36faSFred Richter 	lg_dbg("(%u, %d)\n", state->current_frequency, state->current_modulation);
1014b63b36faSFred Richter 
1015b63b36faSFred Richter 	p->modulation = state->current_modulation;
1016b63b36faSFred Richter 	p->frequency = state->current_frequency;
1017b63b36faSFred Richter 	return 0;
1018b63b36faSFred Richter }
1019b63b36faSFred Richter 
1020b63b36faSFred Richter static enum dvbfe_algo lgdt3306a_get_frontend_algo(struct dvb_frontend *fe)
1021b63b36faSFred Richter {
1022b63b36faSFred Richter #if 1
1023b63b36faSFred Richter 	return DVBFE_ALGO_CUSTOM;
1024b63b36faSFred Richter #else
1025b63b36faSFred Richter 	return DVBFE_ALGO_HW;
1026b63b36faSFred Richter #endif
1027b63b36faSFred Richter }
1028b63b36faSFred Richter 
1029b63b36faSFred Richter /* ------------------------------------------------------------------------ */
1030b63b36faSFred Richter static void lgdt3306a_monitor_vsb(struct lgdt3306a_state *state)
1031b63b36faSFred Richter {
1032b63b36faSFred Richter 	u8 val;
1033b63b36faSFred Richter 	int ret;
1034b63b36faSFred Richter 	u8 snrRef, maxPowerMan, nCombDet;
1035b63b36faSFred Richter 	u16 fbDlyCir;
1036b63b36faSFred Richter 
1037b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x21A1, &val);
1038b63b36faSFred Richter 	snrRef = val & 0x3F;
1039b63b36faSFred Richter 
1040b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2185, &maxPowerMan);
1041b63b36faSFred Richter 
1042b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2191, &val);
1043b63b36faSFred Richter 	nCombDet = (val & 0x80) >> 7;
1044b63b36faSFred Richter 
1045b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2180, &val);
1046b63b36faSFred Richter 	fbDlyCir = (val & 0x03) << 8;
1047b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2181, &val);
1048b63b36faSFred Richter 	fbDlyCir |= val;
1049b63b36faSFred Richter 
1050b63b36faSFred Richter 	lg_dbg("snrRef=%d maxPowerMan=0x%x nCombDet=%d fbDlyCir=0x%x\n",
1051b63b36faSFred Richter 		snrRef, maxPowerMan, nCombDet, fbDlyCir);
1052b63b36faSFred Richter 
10538e8cd34eSMichael Ira Krufky 	/* Carrier offset sub loop bandwidth */
1054b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x1061, &val);
1055b63b36faSFred Richter 	val &= 0xF8;
1056b63b36faSFred Richter 	if ((snrRef > 18) && (maxPowerMan > 0x68) && (nCombDet == 0x01) && ((fbDlyCir == 0x03FF) || (fbDlyCir < 0x6C)))	{
10578e8cd34eSMichael Ira Krufky 		/* SNR is over 18dB and no ghosting */
10588e8cd34eSMichael Ira Krufky 		val |= 0x00; /* final bandwidth = 0 */
1059b63b36faSFred Richter 	} else {
10608e8cd34eSMichael Ira Krufky 		val |= 0x04; /* final bandwidth = 4 */
1061b63b36faSFred Richter 	}
1062b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x1061, val);
1063b63b36faSFred Richter 
10648e8cd34eSMichael Ira Krufky 	/* Adjust Notch Filter */
1065b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0024, &val);
1066b63b36faSFred Richter 	val &= 0x0F;
10678e8cd34eSMichael Ira Krufky 	if (nCombDet == 0) { /* Turn on the Notch Filter */
1068b63b36faSFred Richter 		val |= 0x50;
1069b63b36faSFred Richter 	}
1070b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x0024, val);
1071b63b36faSFred Richter 
10728e8cd34eSMichael Ira Krufky 	/* VSB Timing Recovery output normalization */
1073b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x103D, &val);
1074b63b36faSFred Richter 	val &= 0xCF;
1075b63b36faSFred Richter 	val |= 0x20;
1076b63b36faSFred Richter 	ret = lgdt3306a_write_reg(state, 0x103D, val);
1077b63b36faSFred Richter }
1078b63b36faSFred Richter 
1079f883d603SMichael Ira Krufky static enum lgdt3306a_modulation lgdt3306a_check_oper_mode(struct lgdt3306a_state *state)
1080b63b36faSFred Richter {
1081b63b36faSFred Richter 	u8 val = 0;
1082b63b36faSFred Richter 	int ret;
1083b63b36faSFred Richter 
1084b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0081, &val);
1085b63b36faSFred Richter 
1086b63b36faSFred Richter 	if (val & 0x80)	{
1087b63b36faSFred Richter 		lg_dbg("VSB\n");
10888e8cd34eSMichael Ira Krufky 		return LG3306_VSB;
1089b63b36faSFred Richter 	}
1090c714efe4SMichael Ira Krufky 	if (val & 0x08) {
1091b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x00A6, &val);
1092b63b36faSFred Richter 		val = val >> 2;
1093b63b36faSFred Richter 		if (val & 0x01) {
1094b63b36faSFred Richter 			lg_dbg("QAM256\n");
10958e8cd34eSMichael Ira Krufky 			return LG3306_QAM256;
1096b63b36faSFred Richter 		} else {
1097b63b36faSFred Richter 			lg_dbg("QAM64\n");
10988e8cd34eSMichael Ira Krufky 			return LG3306_QAM64;
1099b63b36faSFred Richter 		}
1100b63b36faSFred Richter 	}
1101b63b36faSFred Richter 	lg_warn("UNKNOWN\n");
11028e8cd34eSMichael Ira Krufky 	return LG3306_UNKNOWN_MODE;
1103b63b36faSFred Richter }
1104b63b36faSFred Richter 
1105f883d603SMichael Ira Krufky static enum lgdt3306a_lock_status lgdt3306a_check_lock_status(struct lgdt3306a_state *state,
1106f883d603SMichael Ira Krufky 			enum lgdt3306a_lock_check whatLock)
1107b63b36faSFred Richter {
1108b63b36faSFred Richter 	u8 val = 0;
1109b63b36faSFred Richter 	int ret;
1110f883d603SMichael Ira Krufky 	enum lgdt3306a_modulation	modeOper;
1111f883d603SMichael Ira Krufky 	enum lgdt3306a_lock_status lockStatus;
1112b63b36faSFred Richter 
1113b63b36faSFred Richter 	modeOper = LG3306_UNKNOWN_MODE;
1114b63b36faSFred Richter 
11158e8cd34eSMichael Ira Krufky 	switch (whatLock) {
1116b63b36faSFred Richter 	case LG3306_SYNC_LOCK:
1117b63b36faSFred Richter 	{
1118b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x00A6, &val);
1119b63b36faSFred Richter 
1120b63b36faSFred Richter 		if ((val & 0x80) == 0x80)
1121b63b36faSFred Richter 			lockStatus = LG3306_LOCK;
1122b63b36faSFred Richter 		else
1123b63b36faSFred Richter 			lockStatus = LG3306_UNLOCK;
1124b63b36faSFred Richter 
1125b63b36faSFred Richter 		lg_dbg("SYNC_LOCK=%x\n", lockStatus);
1126b63b36faSFred Richter 		break;
1127b63b36faSFred Richter 	}
1128b63b36faSFred Richter 	case LG3306_AGC_LOCK:
1129b63b36faSFred Richter 	{
1130b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x0080, &val);
1131b63b36faSFred Richter 
1132b63b36faSFred Richter 		if ((val & 0x40) == 0x40)
1133b63b36faSFred Richter 			lockStatus = LG3306_LOCK;
1134b63b36faSFred Richter 		else
1135b63b36faSFred Richter 			lockStatus = LG3306_UNLOCK;
1136b63b36faSFred Richter 
1137b63b36faSFred Richter 		lg_dbg("AGC_LOCK=%x\n", lockStatus);
1138b63b36faSFred Richter 		break;
1139b63b36faSFred Richter 	}
1140b63b36faSFred Richter 	case LG3306_TR_LOCK:
1141b63b36faSFred Richter 	{
1142b63b36faSFred Richter 		modeOper = lgdt3306a_check_oper_mode(state);
11438e8cd34eSMichael Ira Krufky 		if ((modeOper == LG3306_QAM64) || (modeOper == LG3306_QAM256)) {
1144b63b36faSFred Richter 			ret = lgdt3306a_read_reg(state, 0x1094, &val);
1145b63b36faSFred Richter 
1146b63b36faSFred Richter 			if ((val & 0x80) == 0x80)
1147b63b36faSFred Richter 				lockStatus = LG3306_LOCK;
1148b63b36faSFred Richter 			else
1149b63b36faSFred Richter 				lockStatus = LG3306_UNLOCK;
11508e8cd34eSMichael Ira Krufky 		} else
1151b63b36faSFred Richter 			lockStatus = LG3306_UNKNOWN_LOCK;
1152b63b36faSFred Richter 
1153b63b36faSFred Richter 		lg_dbg("TR_LOCK=%x\n", lockStatus);
1154b63b36faSFred Richter 		break;
1155b63b36faSFred Richter 	}
1156b63b36faSFred Richter 	case LG3306_FEC_LOCK:
1157b63b36faSFred Richter 	{
1158b63b36faSFred Richter 		modeOper = lgdt3306a_check_oper_mode(state);
11598e8cd34eSMichael Ira Krufky 		if ((modeOper == LG3306_QAM64) || (modeOper == LG3306_QAM256)) {
1160b63b36faSFred Richter 			ret = lgdt3306a_read_reg(state, 0x0080, &val);
1161b63b36faSFred Richter 
1162b63b36faSFred Richter 			if ((val & 0x10) == 0x10)
1163b63b36faSFred Richter 				lockStatus = LG3306_LOCK;
1164b63b36faSFred Richter 			else
1165b63b36faSFred Richter 				lockStatus = LG3306_UNLOCK;
11668e8cd34eSMichael Ira Krufky 		} else
1167b63b36faSFred Richter 			lockStatus = LG3306_UNKNOWN_LOCK;
1168b63b36faSFred Richter 
1169b63b36faSFred Richter 		lg_dbg("FEC_LOCK=%x\n", lockStatus);
1170b63b36faSFred Richter 		break;
1171b63b36faSFred Richter 	}
1172b63b36faSFred Richter 
1173b63b36faSFred Richter 	default:
1174b63b36faSFred Richter 		lockStatus = LG3306_UNKNOWN_LOCK;
1175b63b36faSFred Richter 		lg_warn("UNKNOWN whatLock=%d\n", whatLock);
1176b63b36faSFred Richter 		break;
1177b63b36faSFred Richter 	}
1178b63b36faSFred Richter 
11798e8cd34eSMichael Ira Krufky 	return lockStatus;
1180b63b36faSFred Richter }
1181b63b36faSFred Richter 
1182f883d603SMichael Ira Krufky static enum lgdt3306a_neverlock_status lgdt3306a_check_neverlock_status(struct lgdt3306a_state *state)
1183b63b36faSFred Richter {
1184b63b36faSFred Richter 	u8 val = 0;
1185b63b36faSFred Richter 	int ret;
1186f883d603SMichael Ira Krufky 	enum lgdt3306a_neverlock_status lockStatus;
1187b63b36faSFred Richter 
1188b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0080, &val);
1189f883d603SMichael Ira Krufky 	lockStatus = (enum lgdt3306a_neverlock_status)(val & 0x03);
1190b63b36faSFred Richter 
1191b63b36faSFred Richter 	lg_dbg("NeverLock=%d", lockStatus);
1192b63b36faSFred Richter 
11938e8cd34eSMichael Ira Krufky 	return lockStatus;
1194b63b36faSFred Richter }
1195b63b36faSFred Richter 
1196b63b36faSFred Richter static void lgdt3306a_pre_monitoring(struct lgdt3306a_state *state)
1197b63b36faSFred Richter {
1198b63b36faSFred Richter 	u8 val = 0;
1199b63b36faSFred Richter 	int ret;
1200b63b36faSFred Richter 	u8 currChDiffACQ, snrRef, mainStrong, aiccrejStatus;
1201b63b36faSFred Richter 
12028e8cd34eSMichael Ira Krufky 	/* Channel variation */
1203b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x21BC, &currChDiffACQ);
1204b63b36faSFred Richter 
12058e8cd34eSMichael Ira Krufky 	/* SNR of Frame sync */
1206b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x21A1, &val);
1207b63b36faSFred Richter 	snrRef = val & 0x3F;
1208b63b36faSFred Richter 
12098e8cd34eSMichael Ira Krufky 	/* Strong Main CIR */
1210b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x2199, &val);
1211b63b36faSFred Richter 	mainStrong = (val & 0x40) >> 6;
1212b63b36faSFred Richter 
1213b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0090, &val);
1214b63b36faSFred Richter 	aiccrejStatus = (val & 0xF0) >> 4;
1215b63b36faSFred Richter 
1216b63b36faSFred Richter 	lg_dbg("snrRef=%d mainStrong=%d aiccrejStatus=%d currChDiffACQ=0x%x\n",
1217b63b36faSFred Richter 		snrRef, mainStrong, aiccrejStatus, currChDiffACQ);
1218b63b36faSFred Richter 
12198e8cd34eSMichael Ira Krufky #if 0
12208e8cd34eSMichael Ira Krufky 	if ((mainStrong == 0) && (currChDiffACQ > 0x70)) /* Dynamic ghost exists */
12218e8cd34eSMichael Ira Krufky #endif
12228e8cd34eSMichael Ira Krufky 	if (mainStrong == 0) {
1223b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x2135, &val);
1224b63b36faSFred Richter 		val &= 0x0F;
1225b63b36faSFred Richter 		val |= 0xA0;
1226b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2135, val);
1227b63b36faSFred Richter 
1228b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x2141, &val);
1229b63b36faSFred Richter 		val &= 0x3F;
1230b63b36faSFred Richter 		val |= 0x80;
1231b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2141, val);
1232b63b36faSFred Richter 
1233b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2122, 0x70);
12348e8cd34eSMichael Ira Krufky 	} else { /* Weak ghost or static channel */
1235b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x2135, &val);
1236b63b36faSFred Richter 		val &= 0x0F;
1237b63b36faSFred Richter 		val |= 0x70;
1238b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2135, val);
1239b63b36faSFred Richter 
1240b63b36faSFred Richter 		ret = lgdt3306a_read_reg(state, 0x2141, &val);
1241b63b36faSFred Richter 		val &= 0x3F;
1242b63b36faSFred Richter 		val |= 0x40;
1243b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2141, val);
1244b63b36faSFred Richter 
1245b63b36faSFred Richter 		ret = lgdt3306a_write_reg(state, 0x2122, 0x40);
1246b63b36faSFred Richter 	}
1247b63b36faSFred Richter 
1248b63b36faSFred Richter }
1249b63b36faSFred Richter 
1250f883d603SMichael Ira Krufky static enum lgdt3306a_lock_status lgdt3306a_sync_lock_poll(struct lgdt3306a_state *state)
1251b63b36faSFred Richter {
1252f883d603SMichael Ira Krufky 	enum lgdt3306a_lock_status syncLockStatus = LG3306_UNLOCK;
1253b63b36faSFred Richter 	int	i;
1254b63b36faSFred Richter 
1255b63b36faSFred Richter 	for (i = 0; i < 2; i++)	{
1256b63b36faSFred Richter 		msleep(30);
1257b63b36faSFred Richter 
1258b63b36faSFred Richter 		syncLockStatus = lgdt3306a_check_lock_status(state, LG3306_SYNC_LOCK);
1259b63b36faSFred Richter 
1260b63b36faSFred Richter 		if (syncLockStatus == LG3306_LOCK) {
1261b63b36faSFred Richter 			lg_dbg("locked(%d)\n", i);
12628e8cd34eSMichael Ira Krufky 			return LG3306_LOCK;
1263b63b36faSFred Richter 		}
1264b63b36faSFred Richter 	}
1265b63b36faSFred Richter 	lg_dbg("not locked\n");
12668e8cd34eSMichael Ira Krufky 	return LG3306_UNLOCK;
1267b63b36faSFred Richter }
1268b63b36faSFred Richter 
1269f883d603SMichael Ira Krufky static enum lgdt3306a_lock_status lgdt3306a_fec_lock_poll(struct lgdt3306a_state *state)
1270b63b36faSFred Richter {
1271f883d603SMichael Ira Krufky 	enum lgdt3306a_lock_status FECLockStatus = LG3306_UNLOCK;
1272b63b36faSFred Richter 	int	i;
1273b63b36faSFred Richter 
1274b63b36faSFred Richter 	for (i = 0; i < 2; i++)	{
1275b63b36faSFred Richter 		msleep(30);
1276b63b36faSFred Richter 
1277b63b36faSFred Richter 		FECLockStatus = lgdt3306a_check_lock_status(state, LG3306_FEC_LOCK);
1278b63b36faSFred Richter 
1279b63b36faSFred Richter 		if (FECLockStatus == LG3306_LOCK) {
1280b63b36faSFred Richter 			lg_dbg("locked(%d)\n", i);
12818e8cd34eSMichael Ira Krufky 			return FECLockStatus;
1282b63b36faSFred Richter 		}
1283b63b36faSFred Richter 	}
1284b63b36faSFred Richter 	lg_dbg("not locked\n");
12858e8cd34eSMichael Ira Krufky 	return FECLockStatus;
1286b63b36faSFred Richter }
1287b63b36faSFred Richter 
1288f883d603SMichael Ira Krufky static enum lgdt3306a_neverlock_status lgdt3306a_neverlock_poll(struct lgdt3306a_state *state)
1289b63b36faSFred Richter {
1290f883d603SMichael Ira Krufky 	enum lgdt3306a_neverlock_status NLLockStatus = LG3306_NL_FAIL;
1291b63b36faSFred Richter 	int	i;
1292b63b36faSFred Richter 
1293b63b36faSFred Richter 	for (i = 0; i < 5; i++) {
1294b63b36faSFred Richter 		msleep(30);
1295b63b36faSFred Richter 
1296b63b36faSFred Richter 		NLLockStatus = lgdt3306a_check_neverlock_status(state);
1297b63b36faSFred Richter 
1298b63b36faSFred Richter 		if (NLLockStatus == LG3306_NL_LOCK) {
1299b63b36faSFred Richter 			lg_dbg("NL_LOCK(%d)\n", i);
13008e8cd34eSMichael Ira Krufky 			return NLLockStatus;
1301b63b36faSFred Richter 		}
1302b63b36faSFred Richter 	}
1303b63b36faSFred Richter 	lg_dbg("NLLockStatus=%d\n", NLLockStatus);
13048e8cd34eSMichael Ira Krufky 	return NLLockStatus;
1305b63b36faSFred Richter }
1306b63b36faSFred Richter 
1307b63b36faSFred Richter static u8 lgdt3306a_get_packet_error(struct lgdt3306a_state *state)
1308b63b36faSFred Richter {
1309b63b36faSFred Richter 	u8 val;
1310b63b36faSFred Richter 	int ret;
1311b63b36faSFred Richter 
1312b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x00FA, &val);
1313b63b36faSFred Richter 
13148e8cd34eSMichael Ira Krufky 	return val;
1315b63b36faSFred Richter }
1316b63b36faSFred Richter 
1317b63b36faSFred Richter static u32 log10_x1000(u32 x)
1318b63b36faSFred Richter {
1319b63b36faSFred Richter 	static u32 valx_x10[]     = {  10,  11,  13,  15,  17,  20,  25,  33,  41,  50,  59,  73,  87,  100 };
1320b63b36faSFred Richter 	static u32 log10x_x1000[] = {   0,  41, 114, 176, 230, 301, 398, 518, 613, 699, 771, 863, 939, 1000 };
1321b63b36faSFred Richter 	static u32 nelems = sizeof(valx_x10)/sizeof(valx_x10[0]);
1322b63b36faSFred Richter 	u32 log_val = 0;
1323b63b36faSFred Richter 	u32 i;
1324b63b36faSFred Richter 
1325b63b36faSFred Richter 	if (x <= 0)
13268e8cd34eSMichael Ira Krufky 		return -1000000; /* signal error */
1327b63b36faSFred Richter 
1328b63b36faSFred Richter 	if (x < 10) {
1329b63b36faSFred Richter 		while (x < 10) {
1330b63b36faSFred Richter 			x = x * 10;
1331b63b36faSFred Richter 			log_val--;
1332b63b36faSFred Richter 		}
1333b63b36faSFred Richter 	} else if (x == 10) {
13348e8cd34eSMichael Ira Krufky 		return 0; /* log(1)=0 */
1335b63b36faSFred Richter 	} else {
1336b63b36faSFred Richter 		while (x >= 100) {
1337b63b36faSFred Richter 			x = x / 10;
1338b63b36faSFred Richter 			log_val++;
1339b63b36faSFred Richter 		}
1340b63b36faSFred Richter 	}
1341b63b36faSFred Richter 	log_val *= 1000;
1342b63b36faSFred Richter 
13438e8cd34eSMichael Ira Krufky 	if (x == 10) /* was our input an exact multiple of 10 */
13448e8cd34eSMichael Ira Krufky 		return log_val;	/* don't need to interpolate */
1345b63b36faSFred Richter 
13468e8cd34eSMichael Ira Krufky 	/* find our place on the log curve */
1347b63b36faSFred Richter 	for (i = 1; i < nelems; i++) {
13488e8cd34eSMichael Ira Krufky 		if (valx_x10[i] >= x)
13498e8cd34eSMichael Ira Krufky 			break;
1350b63b36faSFred Richter 	}
1351b63b36faSFred Richter 
1352b63b36faSFred Richter 	{
1353b63b36faSFred Richter 		u32 diff_val   = x - valx_x10[i-1];
1354b63b36faSFred Richter 		u32 step_val   = valx_x10[i] - valx_x10[i-1];
1355b63b36faSFred Richter 		u32 step_log10 = log10x_x1000[i] - log10x_x1000[i-1];
13568e8cd34eSMichael Ira Krufky 		/* do a linear interpolation to get in-between values */
13578e8cd34eSMichael Ira Krufky 		return log_val + log10x_x1000[i-1] +
13588e8cd34eSMichael Ira Krufky 			((diff_val*step_log10) / step_val);
1359b63b36faSFred Richter 	}
1360b63b36faSFred Richter }
1361b63b36faSFred Richter 
1362b63b36faSFred Richter static u32 lgdt3306a_calculate_snr_x100(struct lgdt3306a_state *state)
1363b63b36faSFred Richter {
1364b63b36faSFred Richter 	u32 mse;  /* Mean-Square Error */
1365b63b36faSFred Richter 	u32 pwr;  /* Constelation power */
1366b63b36faSFred Richter 	u32 snr_x100;
1367b63b36faSFred Richter 
1368b63b36faSFred Richter 	mse = (read_reg(state, 0x00EC) << 8) |
1369b63b36faSFred Richter 	      (read_reg(state, 0x00ED));
1370b63b36faSFred Richter 	pwr = (read_reg(state, 0x00E8) << 8) |
1371b63b36faSFred Richter 	      (read_reg(state, 0x00E9));
1372b63b36faSFred Richter 
1373b63b36faSFred Richter 	if (mse == 0) /* no signal */
1374b63b36faSFred Richter 		return 0;
1375b63b36faSFred Richter 
1376b63b36faSFred Richter 	snr_x100 = log10_x1000((pwr * 10000) / mse) - 3000;
1377b63b36faSFred Richter 	lg_dbg("mse=%u, pwr=%u, snr_x100=%d\n", mse, pwr, snr_x100);
1378b63b36faSFred Richter 
1379b63b36faSFred Richter 	return snr_x100;
1380b63b36faSFred Richter }
1381b63b36faSFred Richter 
1382f883d603SMichael Ira Krufky static enum lgdt3306a_lock_status lgdt3306a_vsb_lock_poll(struct lgdt3306a_state *state)
1383b63b36faSFred Richter {
1384b63b36faSFred Richter 	u8 cnt = 0;
1385b63b36faSFred Richter 	u8 packet_error;
1386b63b36faSFred Richter 	u32 snr;
1387b63b36faSFred Richter 
1388b63b36faSFred Richter 	while (1) {
1389b63b36faSFred Richter 		if (lgdt3306a_sync_lock_poll(state) == LG3306_UNLOCK) {
1390b63b36faSFred Richter 			lg_dbg("no sync lock!\n");
13918e8cd34eSMichael Ira Krufky 			return LG3306_UNLOCK;
1392b63b36faSFred Richter 		} else {
1393b63b36faSFred Richter 			msleep(20);
1394b63b36faSFred Richter 			lgdt3306a_pre_monitoring(state);
1395b63b36faSFred Richter 
1396b63b36faSFred Richter 			packet_error = lgdt3306a_get_packet_error(state);
1397b63b36faSFred Richter 			snr = lgdt3306a_calculate_snr_x100(state);
13988e8cd34eSMichael Ira Krufky 			lg_dbg("cnt=%d errors=%d snr=%d\n",
13998e8cd34eSMichael Ira Krufky 			       cnt, packet_error, snr);
1400b63b36faSFred Richter 
14018e8cd34eSMichael Ira Krufky 			if ((snr < 1500) || (packet_error >= 0xff))
1402b63b36faSFred Richter 				cnt++;
14038e8cd34eSMichael Ira Krufky 			else
14048e8cd34eSMichael Ira Krufky 				return LG3306_LOCK;
1405b63b36faSFred Richter 
1406b63b36faSFred Richter 			if (cnt >= 10) {
1407b63b36faSFred Richter 				lg_dbg("not locked!\n");
14088e8cd34eSMichael Ira Krufky 				return LG3306_UNLOCK;
1409b63b36faSFred Richter 			}
1410b63b36faSFred Richter 		}
1411b63b36faSFred Richter 	}
14128e8cd34eSMichael Ira Krufky 	return LG3306_UNLOCK;
1413b63b36faSFred Richter }
1414b63b36faSFred Richter 
1415f883d603SMichael Ira Krufky static enum lgdt3306a_lock_status lgdt3306a_qam_lock_poll(struct lgdt3306a_state *state)
1416b63b36faSFred Richter {
1417b63b36faSFred Richter 	u8 cnt = 0;
1418b63b36faSFred Richter 	u8 packet_error;
1419b63b36faSFred Richter 	u32	snr;
1420b63b36faSFred Richter 
1421b63b36faSFred Richter 	while (1) {
1422b63b36faSFred Richter 		if (lgdt3306a_fec_lock_poll(state) == LG3306_UNLOCK) {
1423b63b36faSFred Richter 			lg_dbg("no fec lock!\n");
14248e8cd34eSMichael Ira Krufky 			return LG3306_UNLOCK;
1425b63b36faSFred Richter 		} else {
1426b63b36faSFred Richter 			msleep(20);
1427b63b36faSFred Richter 
1428b63b36faSFred Richter 			packet_error = lgdt3306a_get_packet_error(state);
1429b63b36faSFred Richter 			snr = lgdt3306a_calculate_snr_x100(state);
14308e8cd34eSMichael Ira Krufky 			lg_dbg("cnt=%d errors=%d snr=%d\n",
14318e8cd34eSMichael Ira Krufky 			       cnt, packet_error, snr);
1432b63b36faSFred Richter 
14338e8cd34eSMichael Ira Krufky 			if ((snr < 1500) || (packet_error >= 0xff))
1434b63b36faSFred Richter 				cnt++;
14358e8cd34eSMichael Ira Krufky 			else
14368e8cd34eSMichael Ira Krufky 				return LG3306_LOCK;
1437b63b36faSFred Richter 
1438b63b36faSFred Richter 			if (cnt >= 10) {
1439b63b36faSFred Richter 				lg_dbg("not locked!\n");
14408e8cd34eSMichael Ira Krufky 				return LG3306_UNLOCK;
1441b63b36faSFred Richter 			}
1442b63b36faSFred Richter 		}
1443b63b36faSFred Richter 	}
14448e8cd34eSMichael Ira Krufky 	return LG3306_UNLOCK;
1445b63b36faSFred Richter }
1446b63b36faSFred Richter 
1447b63b36faSFred Richter static int lgdt3306a_read_status(struct dvb_frontend *fe, fe_status_t *status)
1448b63b36faSFred Richter {
1449b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1450b63b36faSFred Richter 	u16 strength = 0;
14518e8cd34eSMichael Ira Krufky 	int ret = 0;
14528e8cd34eSMichael Ira Krufky 
1453b63b36faSFred Richter 	if (fe->ops.tuner_ops.get_rf_strength) {
1454b63b36faSFred Richter 		ret = fe->ops.tuner_ops.get_rf_strength(fe, &strength);
1455b63b36faSFred Richter 		if (ret == 0) {
1456b63b36faSFred Richter 			lg_dbg("strength=%d\n", strength);
1457b63b36faSFred Richter 		} else {
1458b63b36faSFred Richter 			lg_dbg("fe->ops.tuner_ops.get_rf_strength() failed\n");
1459b63b36faSFred Richter 		}
1460b63b36faSFred Richter 	}
1461b63b36faSFred Richter 
1462b63b36faSFred Richter 	*status = 0;
1463b63b36faSFred Richter 	if (lgdt3306a_neverlock_poll(state) == LG3306_NL_LOCK) {
1464b63b36faSFred Richter 		*status |= FE_HAS_SIGNAL;
1465b63b36faSFred Richter 		*status |= FE_HAS_CARRIER;
1466b63b36faSFred Richter 
1467b63b36faSFred Richter 		switch (state->current_modulation) {
1468b63b36faSFred Richter 		case QAM_256:
1469b63b36faSFred Richter 		case QAM_64:
1470b63b36faSFred Richter 			if (lgdt3306a_qam_lock_poll(state) == LG3306_LOCK) {
1471b63b36faSFred Richter 				*status |= FE_HAS_VITERBI;
1472b63b36faSFred Richter 				*status |= FE_HAS_SYNC;
1473b63b36faSFred Richter 
1474b63b36faSFred Richter 				*status |= FE_HAS_LOCK;
1475b63b36faSFred Richter 			}
1476b63b36faSFred Richter 			break;
1477b63b36faSFred Richter 		case VSB_8:
1478b63b36faSFred Richter 			if (lgdt3306a_vsb_lock_poll(state) == LG3306_LOCK) {
1479b63b36faSFred Richter 				*status |= FE_HAS_VITERBI;
1480b63b36faSFred Richter 				*status |= FE_HAS_SYNC;
1481b63b36faSFred Richter 
1482b63b36faSFred Richter 				*status |= FE_HAS_LOCK;
1483b63b36faSFred Richter 
1484b63b36faSFred Richter 				lgdt3306a_monitor_vsb(state);
1485b63b36faSFred Richter 			}
1486b63b36faSFred Richter 			break;
1487b63b36faSFred Richter 		default:
1488b63b36faSFred Richter 			ret = -EINVAL;
1489b63b36faSFred Richter 		}
1490b63b36faSFred Richter 	}
1491b63b36faSFred Richter 	return ret;
1492b63b36faSFred Richter }
1493b63b36faSFred Richter 
1494b63b36faSFred Richter 
1495b63b36faSFred Richter static int lgdt3306a_read_snr(struct dvb_frontend *fe, u16 *snr)
1496b63b36faSFred Richter {
1497b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1498b63b36faSFred Richter 
1499b63b36faSFred Richter 	state->snr = lgdt3306a_calculate_snr_x100(state);
1500b63b36faSFred Richter 	/* report SNR in dB * 10 */
1501b63b36faSFred Richter 	*snr = state->snr/10;
1502b63b36faSFred Richter 
1503b63b36faSFred Richter 	return 0;
1504b63b36faSFred Richter }
1505b63b36faSFred Richter 
1506b63b36faSFred Richter static int lgdt3306a_read_signal_strength(struct dvb_frontend *fe,
1507b63b36faSFred Richter 					 u16 *strength)
1508b63b36faSFred Richter {
1509b63b36faSFred Richter 	/*
1510b63b36faSFred Richter 	 * Calculate some sort of "strength" from SNR
1511b63b36faSFred Richter 	 */
1512b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
15138e8cd34eSMichael Ira Krufky 	u16 snr;  /* snr_x10 */
1514b63b36faSFred Richter 	int ret;
15158e8cd34eSMichael Ira Krufky 	u32 ref_snr; /* snr*100 */
1516b63b36faSFred Richter 	u32 str;
1517b63b36faSFred Richter 
1518b63b36faSFred Richter 	*strength = 0;
1519b63b36faSFred Richter 
1520b63b36faSFred Richter 	switch (state->current_modulation) {
1521b63b36faSFred Richter 	case VSB_8:
15228e8cd34eSMichael Ira Krufky 		 ref_snr = 1600; /* 16dB */
1523b63b36faSFred Richter 		 break;
1524b63b36faSFred Richter 	case QAM_64:
15258e8cd34eSMichael Ira Krufky 		 ref_snr = 2200; /* 22dB */
1526b63b36faSFred Richter 		 break;
1527b63b36faSFred Richter 	case QAM_256:
15288e8cd34eSMichael Ira Krufky 		 ref_snr = 2800; /* 28dB */
1529b63b36faSFred Richter 		 break;
1530b63b36faSFred Richter 	default:
1531b63b36faSFred Richter 		return -EINVAL;
1532b63b36faSFred Richter 	}
1533b63b36faSFred Richter 
1534b63b36faSFred Richter 	ret = fe->ops.read_snr(fe, &snr);
1535b63b36faSFred Richter 	if (lg_chkerr(ret))
1536b63b36faSFred Richter 		goto fail;
1537b63b36faSFred Richter 
1538b63b36faSFred Richter 	if (state->snr <= (ref_snr - 100))
1539b63b36faSFred Richter 		str = 0;
1540b63b36faSFred Richter 	else if (state->snr <= ref_snr)
15418e8cd34eSMichael Ira Krufky 		str = (0xffff * 65) / 100; /* 65% */
1542b63b36faSFred Richter 	else {
1543b63b36faSFred Richter 		str = state->snr - ref_snr;
1544b63b36faSFred Richter 		str /= 50;
15458e8cd34eSMichael Ira Krufky 		str += 78; /* 78%-100% */
1546b63b36faSFred Richter 		if (str > 100)
1547b63b36faSFred Richter 			str = 100;
1548b63b36faSFred Richter 		str = (0xffff * str) / 100;
1549b63b36faSFred Richter 	}
1550b63b36faSFred Richter 	*strength = (u16)str;
1551b63b36faSFred Richter 	lg_dbg("strength=%u\n", *strength);
1552b63b36faSFred Richter 
1553b63b36faSFred Richter fail:
1554b63b36faSFred Richter 	return ret;
1555b63b36faSFred Richter }
1556b63b36faSFred Richter 
1557b63b36faSFred Richter /* ------------------------------------------------------------------------ */
1558b63b36faSFred Richter 
1559b63b36faSFred Richter static int lgdt3306a_read_ber(struct dvb_frontend *fe, u32 *ber)
1560b63b36faSFred Richter {
1561b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1562b63b36faSFred Richter 	u32 tmp;
1563b63b36faSFred Richter 
1564b63b36faSFred Richter 	*ber = 0;
1565b63b36faSFred Richter #if 1
15668e8cd34eSMichael Ira Krufky 	/* FGR - BUGBUG - I don't know what value is expected by dvb_core
15678e8cd34eSMichael Ira Krufky 	 * what is the scale of the value?? */
15688e8cd34eSMichael Ira Krufky 	tmp =              read_reg(state, 0x00FC); /* NBERVALUE[24-31] */
15698e8cd34eSMichael Ira Krufky 	tmp = (tmp << 8) | read_reg(state, 0x00FD); /* NBERVALUE[16-23] */
15708e8cd34eSMichael Ira Krufky 	tmp = (tmp << 8) | read_reg(state, 0x00FE); /* NBERVALUE[8-15] */
15718e8cd34eSMichael Ira Krufky 	tmp = (tmp << 8) | read_reg(state, 0x00FF); /* NBERVALUE[0-7] */
1572b63b36faSFred Richter 	*ber = tmp;
1573b63b36faSFred Richter 	lg_dbg("ber=%u\n", tmp);
1574b63b36faSFred Richter #endif
1575b63b36faSFred Richter 	return 0;
1576b63b36faSFred Richter }
1577b63b36faSFred Richter 
1578b63b36faSFred Richter static int lgdt3306a_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1579b63b36faSFred Richter {
1580b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1581b63b36faSFred Richter 
1582b63b36faSFred Richter 	*ucblocks = 0;
1583b63b36faSFred Richter #if 1
15848e8cd34eSMichael Ira Krufky 	/* FGR - BUGBUG - I don't know what value is expected by dvb_core
15858e8cd34eSMichael Ira Krufky 	 * what happens when value wraps? */
15868e8cd34eSMichael Ira Krufky 	*ucblocks = read_reg(state, 0x00F4); /* TPIFTPERRCNT[0-7] */
1587b63b36faSFred Richter 	lg_dbg("ucblocks=%u\n", *ucblocks);
1588b63b36faSFred Richter #endif
1589b63b36faSFred Richter 
1590b63b36faSFred Richter 	return 0;
1591b63b36faSFred Richter }
1592b63b36faSFred Richter 
1593b63b36faSFred Richter static int lgdt3306a_tune(struct dvb_frontend *fe, bool re_tune, unsigned int mode_flags, unsigned int *delay, fe_status_t *status)
1594b63b36faSFred Richter {
1595b63b36faSFred Richter 	int ret = 0;
1596b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
1597b63b36faSFred Richter 
1598b63b36faSFred Richter 	lg_dbg("re_tune=%u\n", re_tune);
1599b63b36faSFred Richter 
1600b63b36faSFred Richter 	if (re_tune) {
16018e8cd34eSMichael Ira Krufky 		state->current_frequency = -1; /* force re-tune */
1602ae21e447SMichael Ira Krufky 		ret = lgdt3306a_set_parameters(fe);
1603ae21e447SMichael Ira Krufky 		if (ret != 0)
1604b63b36faSFred Richter 			return ret;
1605b63b36faSFred Richter 	}
1606b63b36faSFred Richter 	*delay = 125;
1607b63b36faSFred Richter 	ret = lgdt3306a_read_status(fe, status);
1608b63b36faSFred Richter 
1609b63b36faSFred Richter 	return ret;
1610b63b36faSFred Richter }
1611b63b36faSFred Richter 
1612b63b36faSFred Richter static int lgdt3306a_get_tune_settings(struct dvb_frontend *fe,
1613b63b36faSFred Richter 				       struct dvb_frontend_tune_settings
1614b63b36faSFred Richter 				       *fe_tune_settings)
1615b63b36faSFred Richter {
1616b63b36faSFred Richter 	fe_tune_settings->min_delay_ms = 100;
1617b63b36faSFred Richter 	lg_dbg("\n");
1618b63b36faSFred Richter 	return 0;
1619b63b36faSFred Richter }
1620b63b36faSFred Richter 
1621b63b36faSFred Richter static int lgdt3306a_search(struct dvb_frontend *fe)
1622b63b36faSFred Richter {
1623b63b36faSFred Richter 	fe_status_t status = 0;
1624b63b36faSFred Richter 	int i, ret;
1625b63b36faSFred Richter 
1626b63b36faSFred Richter 	/* set frontend */
1627b63b36faSFred Richter 	ret = lgdt3306a_set_parameters(fe);
1628b63b36faSFred Richter 	if (ret)
1629b63b36faSFred Richter 		goto error;
1630b63b36faSFred Richter 
1631b63b36faSFred Richter 	/* wait frontend lock */
1632b63b36faSFred Richter 	for (i = 20; i > 0; i--) {
1633b63b36faSFred Richter 		lg_dbg(": loop=%d\n", i);
1634b63b36faSFred Richter 		msleep(50);
1635b63b36faSFred Richter 		ret = lgdt3306a_read_status(fe, &status);
1636b63b36faSFred Richter 		if (ret)
1637b63b36faSFred Richter 			goto error;
1638b63b36faSFred Richter 
1639b63b36faSFred Richter 		if (status & FE_HAS_LOCK)
1640b63b36faSFred Richter 			break;
1641b63b36faSFred Richter 	}
1642b63b36faSFred Richter 
1643b63b36faSFred Richter 	/* check if we have a valid signal */
16448e8cd34eSMichael Ira Krufky 	if (status & FE_HAS_LOCK)
1645b63b36faSFred Richter 		return DVBFE_ALGO_SEARCH_SUCCESS;
16468e8cd34eSMichael Ira Krufky 	else
1647b63b36faSFred Richter 		return DVBFE_ALGO_SEARCH_AGAIN;
1648b63b36faSFred Richter 
1649b63b36faSFred Richter error:
1650b63b36faSFred Richter 	lg_dbg("failed (%d)\n", ret);
1651b63b36faSFred Richter 	return DVBFE_ALGO_SEARCH_ERROR;
1652b63b36faSFred Richter }
1653b63b36faSFred Richter 
1654b63b36faSFred Richter static void lgdt3306a_release(struct dvb_frontend *fe)
1655b63b36faSFred Richter {
1656b63b36faSFred Richter 	struct lgdt3306a_state *state = fe->demodulator_priv;
16578e8cd34eSMichael Ira Krufky 
1658b63b36faSFred Richter 	lg_dbg("\n");
1659b63b36faSFred Richter 	kfree(state);
1660b63b36faSFred Richter }
1661b63b36faSFred Richter 
1662b63b36faSFred Richter static struct dvb_frontend_ops lgdt3306a_ops;
1663b63b36faSFred Richter 
1664b63b36faSFred Richter struct dvb_frontend *lgdt3306a_attach(const struct lgdt3306a_config *config,
1665b63b36faSFred Richter 				     struct i2c_adapter *i2c_adap)
1666b63b36faSFred Richter {
1667b63b36faSFred Richter 	struct lgdt3306a_state *state = NULL;
1668b63b36faSFred Richter 	int ret;
1669b63b36faSFred Richter 	u8 val;
1670b63b36faSFred Richter 
1671b63b36faSFred Richter 	lg_dbg("(%d-%04x)\n",
1672b63b36faSFred Richter 	       i2c_adap ? i2c_adapter_id(i2c_adap) : 0,
1673b63b36faSFred Richter 	       config ? config->i2c_addr : 0);
1674b63b36faSFred Richter 
1675b63b36faSFred Richter 	state = kzalloc(sizeof(struct lgdt3306a_state), GFP_KERNEL);
1676b63b36faSFred Richter 	if (state == NULL)
1677b63b36faSFred Richter 		goto fail;
1678b63b36faSFred Richter 
1679b63b36faSFred Richter 	state->cfg = config;
1680b63b36faSFred Richter 	state->i2c_adap = i2c_adap;
1681b63b36faSFred Richter 
1682b63b36faSFred Richter 	memcpy(&state->frontend.ops, &lgdt3306a_ops,
1683b63b36faSFred Richter 	       sizeof(struct dvb_frontend_ops));
1684b63b36faSFred Richter 	state->frontend.demodulator_priv = state;
1685b63b36faSFred Richter 
1686b63b36faSFred Richter 	/* verify that we're talking to a lg3306a */
16878e8cd34eSMichael Ira Krufky 	/* FGR - NOTE - there is no obvious ChipId to check; we check
16888e8cd34eSMichael Ira Krufky 	 * some "known" bits after reset, but it's still just a guess */
1689b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0000, &val);
1690b63b36faSFred Richter 	if (lg_chkerr(ret))
1691b63b36faSFred Richter 		goto fail;
1692b63b36faSFred Richter 	if ((val & 0x74) != 0x74) {
1693b63b36faSFred Richter 		lg_warn("expected 0x74, got 0x%x\n", (val & 0x74));
16948e8cd34eSMichael Ira Krufky #if 0
16958e8cd34eSMichael Ira Krufky 		goto fail;	/* BUGBUG - re-enable when we know this is right */
16968e8cd34eSMichael Ira Krufky #endif
1697b63b36faSFred Richter 	}
1698b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0001, &val);
1699b63b36faSFred Richter 	if (lg_chkerr(ret))
1700b63b36faSFred Richter 		goto fail;
1701b63b36faSFred Richter 	if ((val & 0xF6) != 0xC6) {
1702b63b36faSFred Richter 		lg_warn("expected 0xC6, got 0x%x\n", (val & 0xF6));
17038e8cd34eSMichael Ira Krufky #if 0
17048e8cd34eSMichael Ira Krufky 		goto fail;	/* BUGBUG - re-enable when we know this is right */
17058e8cd34eSMichael Ira Krufky #endif
1706b63b36faSFred Richter 	}
1707b63b36faSFred Richter 	ret = lgdt3306a_read_reg(state, 0x0002, &val);
1708b63b36faSFred Richter 	if (lg_chkerr(ret))
1709b63b36faSFred Richter 		goto fail;
1710b63b36faSFred Richter 	if ((val & 0x73) != 0x03) {
1711b63b36faSFred Richter 		lg_warn("expected 0x03, got 0x%x\n", (val & 0x73));
17128e8cd34eSMichael Ira Krufky #if 0
17138e8cd34eSMichael Ira Krufky 		goto fail;	/* BUGBUG - re-enable when we know this is right */
17148e8cd34eSMichael Ira Krufky #endif
1715b63b36faSFred Richter 	}
1716b63b36faSFred Richter 
1717b63b36faSFred Richter 	state->current_frequency = -1;
1718b63b36faSFred Richter 	state->current_modulation = -1;
1719b63b36faSFred Richter 
1720b63b36faSFred Richter 	lgdt3306a_sleep(state);
1721b63b36faSFred Richter 
1722b63b36faSFred Richter 	return &state->frontend;
1723b63b36faSFred Richter 
1724b63b36faSFred Richter fail:
1725b63b36faSFred Richter 	lg_warn("unable to detect LGDT3306A hardware\n");
1726b63b36faSFred Richter 	kfree(state);
1727b63b36faSFred Richter 	return NULL;
1728b63b36faSFred Richter }
1729ebd9175eSMichael Ira Krufky EXPORT_SYMBOL(lgdt3306a_attach);
1730b63b36faSFred Richter 
1731b63b36faSFred Richter #ifdef DBG_DUMP
1732b63b36faSFred Richter 
1733b63b36faSFred Richter static const short regtab[] = {
17346da7ac98SMichael Ira Krufky 	0x0000, /* SOFTRSTB 1'b1 1'b1 1'b1 ADCPDB 1'b1 PLLPDB GBBPDB 11111111 */
17356da7ac98SMichael Ira Krufky 	0x0001, /* 1'b1 1'b1 1'b0 1'b0 AUTORPTRS */
17366da7ac98SMichael Ira Krufky 	0x0002, /* NI2CRPTEN 1'b0 1'b0 1'b0 SPECINVAUT */
17376da7ac98SMichael Ira Krufky 	0x0003, /* AGCRFOUT */
17386da7ac98SMichael Ira Krufky 	0x0004, /* ADCSEL1V ADCCNT ADCCNF ADCCNS ADCCLKPLL */
17396da7ac98SMichael Ira Krufky 	0x0005, /* PLLINDIVSE */
17406da7ac98SMichael Ira Krufky 	0x0006, /* PLLCTRL[7:0] 11100001 */
17416da7ac98SMichael Ira Krufky 	0x0007, /* SYSINITWAITTIME[7:0] (msec) 00001000 */
17426da7ac98SMichael Ira Krufky 	0x0008, /* STDOPMODE[7:0] 10000000 */
17436da7ac98SMichael Ira Krufky 	0x0009, /* 1'b0 1'b0 1'b0 STDOPDETTMODE[2:0] STDOPDETCMODE[1:0] 00011110 */
17446da7ac98SMichael Ira Krufky 	0x000A, /* DAFTEN 1'b1 x x SCSYSLOCK */
17456da7ac98SMichael Ira Krufky 	0x000B, /* SCSYSLOCKCHKTIME[7:0] (10msec) 01100100 */
17466da7ac98SMichael Ira Krufky 	0x000D, /* x SAMPLING4 */
17476da7ac98SMichael Ira Krufky 	0x000E, /* SAMFREQ[15:8] 00000000 */
17486da7ac98SMichael Ira Krufky 	0x000F, /* SAMFREQ[7:0] 00000000 */
17496da7ac98SMichael Ira Krufky 	0x0010, /* IFFREQ[15:8] 01100000 */
17506da7ac98SMichael Ira Krufky 	0x0011, /* IFFREQ[7:0] 00000000 */
17516da7ac98SMichael Ira Krufky 	0x0012, /* AGCEN AGCREFMO */
17526da7ac98SMichael Ira Krufky 	0x0013, /* AGCRFFIXB AGCIFFIXB AGCLOCKDETRNGSEL[1:0] 1'b1 1'b0 1'b0 1'b0 11101000 */
17536da7ac98SMichael Ira Krufky 	0x0014, /* AGCFIXVALUE[7:0] 01111111 */
17546da7ac98SMichael Ira Krufky 	0x0015, /* AGCREF[15:8] 00001010 */
17556da7ac98SMichael Ira Krufky 	0x0016, /* AGCREF[7:0] 11100100 */
17566da7ac98SMichael Ira Krufky 	0x0017, /* AGCDELAY[7:0] 00100000 */
17576da7ac98SMichael Ira Krufky 	0x0018, /* AGCRFBW[3:0] AGCIFBW[3:0] 10001000 */
17586da7ac98SMichael Ira Krufky 	0x0019, /* AGCUDOUTMODE[1:0] AGCUDCTRLLEN[1:0] AGCUDCTRL */
17596da7ac98SMichael Ira Krufky 	0x001C, /* 1'b1 PFEN MFEN AICCVSYNC */
17606da7ac98SMichael Ira Krufky 	0x001D, /* 1'b0 1'b1 1'b0 1'b1 AICCVSYNC */
17616da7ac98SMichael Ira Krufky 	0x001E, /* AICCALPHA[3:0] 1'b1 1'b0 1'b1 1'b0 01111010 */
17626da7ac98SMichael Ira Krufky 	0x001F, /* AICCDETTH[19:16] AICCOFFTH[19:16] 00000000 */
17636da7ac98SMichael Ira Krufky 	0x0020, /* AICCDETTH[15:8] 01111100 */
17646da7ac98SMichael Ira Krufky 	0x0021, /* AICCDETTH[7:0] 00000000 */
17656da7ac98SMichael Ira Krufky 	0x0022, /* AICCOFFTH[15:8] 00000101 */
17666da7ac98SMichael Ira Krufky 	0x0023, /* AICCOFFTH[7:0] 11100000 */
17676da7ac98SMichael Ira Krufky 	0x0024, /* AICCOPMODE3[1:0] AICCOPMODE2[1:0] AICCOPMODE1[1:0] AICCOPMODE0[1:0] 00000000 */
17686da7ac98SMichael Ira Krufky 	0x0025, /* AICCFIXFREQ3[23:16] 00000000 */
17696da7ac98SMichael Ira Krufky 	0x0026, /* AICCFIXFREQ3[15:8] 00000000 */
17706da7ac98SMichael Ira Krufky 	0x0027, /* AICCFIXFREQ3[7:0] 00000000 */
17716da7ac98SMichael Ira Krufky 	0x0028, /* AICCFIXFREQ2[23:16] 00000000 */
17726da7ac98SMichael Ira Krufky 	0x0029, /* AICCFIXFREQ2[15:8] 00000000 */
17736da7ac98SMichael Ira Krufky 	0x002A, /* AICCFIXFREQ2[7:0] 00000000 */
17746da7ac98SMichael Ira Krufky 	0x002B, /* AICCFIXFREQ1[23:16] 00000000 */
17756da7ac98SMichael Ira Krufky 	0x002C, /* AICCFIXFREQ1[15:8] 00000000 */
17766da7ac98SMichael Ira Krufky 	0x002D, /* AICCFIXFREQ1[7:0] 00000000 */
17776da7ac98SMichael Ira Krufky 	0x002E, /* AICCFIXFREQ0[23:16] 00000000 */
17786da7ac98SMichael Ira Krufky 	0x002F, /* AICCFIXFREQ0[15:8] 00000000 */
17796da7ac98SMichael Ira Krufky 	0x0030, /* AICCFIXFREQ0[7:0] 00000000 */
17806da7ac98SMichael Ira Krufky 	0x0031, /* 1'b0 1'b1 1'b0 1'b0 x DAGC1STER */
17816da7ac98SMichael Ira Krufky 	0x0032, /* DAGC1STEN DAGC1STER */
17826da7ac98SMichael Ira Krufky 	0x0033, /* DAGC1STREF[15:8] 00001010 */
17836da7ac98SMichael Ira Krufky 	0x0034, /* DAGC1STREF[7:0] 11100100 */
17846da7ac98SMichael Ira Krufky 	0x0035, /* DAGC2NDE */
17856da7ac98SMichael Ira Krufky 	0x0036, /* DAGC2NDREF[15:8] 00001010 */
17866da7ac98SMichael Ira Krufky 	0x0037, /* DAGC2NDREF[7:0] 10000000 */
17876da7ac98SMichael Ira Krufky 	0x0038, /* DAGC2NDLOCKDETRNGSEL[1:0] */
17886da7ac98SMichael Ira Krufky 	0x003D, /* 1'b1 SAMGEARS */
17896da7ac98SMichael Ira Krufky 	0x0040, /* SAMLFGMA */
17906da7ac98SMichael Ira Krufky 	0x0041, /* SAMLFBWM */
17916da7ac98SMichael Ira Krufky 	0x0044, /* 1'b1 CRGEARSHE */
17926da7ac98SMichael Ira Krufky 	0x0045, /* CRLFGMAN */
17936da7ac98SMichael Ira Krufky 	0x0046, /* CFLFBWMA */
17946da7ac98SMichael Ira Krufky 	0x0047, /* CRLFGMAN */
17956da7ac98SMichael Ira Krufky 	0x0048, /* x x x x CRLFGSTEP_VS[3:0] xxxx1001 */
17966da7ac98SMichael Ira Krufky 	0x0049, /* CRLFBWMA */
17976da7ac98SMichael Ira Krufky 	0x004A, /* CRLFBWMA */
17986da7ac98SMichael Ira Krufky 	0x0050, /* 1'b0 1'b1 1'b1 1'b0 MSECALCDA */
17996da7ac98SMichael Ira Krufky 	0x0070, /* TPOUTEN TPIFEN TPCLKOUTE */
18006da7ac98SMichael Ira Krufky 	0x0071, /* TPSENB TPSSOPBITE */
18016da7ac98SMichael Ira Krufky 	0x0073, /* TP47HINS x x CHBERINT PERMODE[1:0] PERINT[1:0] 1xx11100 */
18026da7ac98SMichael Ira Krufky 	0x0075, /* x x x x x IQSWAPCTRL[2:0] xxxxx000 */
18036da7ac98SMichael Ira Krufky 	0x0076, /* NBERCON NBERST NBERPOL NBERWSYN */
18046da7ac98SMichael Ira Krufky 	0x0077, /* x NBERLOSTTH[2:0] NBERACQTH[3:0] x0000000 */
18056da7ac98SMichael Ira Krufky 	0x0078, /* NBERPOLY[31:24] 00000000 */
18066da7ac98SMichael Ira Krufky 	0x0079, /* NBERPOLY[23:16] 00000000 */
18076da7ac98SMichael Ira Krufky 	0x007A, /* NBERPOLY[15:8] 00000000 */
18086da7ac98SMichael Ira Krufky 	0x007B, /* NBERPOLY[7:0] 00000000 */
18096da7ac98SMichael Ira Krufky 	0x007C, /* NBERPED[31:24] 00000000 */
18106da7ac98SMichael Ira Krufky 	0x007D, /* NBERPED[23:16] 00000000 */
18116da7ac98SMichael Ira Krufky 	0x007E, /* NBERPED[15:8] 00000000 */
18126da7ac98SMichael Ira Krufky 	0x007F, /* NBERPED[7:0] 00000000 */
18136da7ac98SMichael Ira Krufky 	0x0080, /* x AGCLOCK DAGCLOCK SYSLOCK x x NEVERLOCK[1:0] */
18146da7ac98SMichael Ira Krufky 	0x0085, /* SPECINVST */
18156da7ac98SMichael Ira Krufky 	0x0088, /* SYSLOCKTIME[15:8] */
18166da7ac98SMichael Ira Krufky 	0x0089, /* SYSLOCKTIME[7:0] */
18176da7ac98SMichael Ira Krufky 	0x008C, /* FECLOCKTIME[15:8] */
18186da7ac98SMichael Ira Krufky 	0x008D, /* FECLOCKTIME[7:0] */
18196da7ac98SMichael Ira Krufky 	0x008E, /* AGCACCOUT[15:8] */
18206da7ac98SMichael Ira Krufky 	0x008F, /* AGCACCOUT[7:0] */
18216da7ac98SMichael Ira Krufky 	0x0090, /* AICCREJSTATUS[3:0] AICCREJBUSY[3:0] */
18226da7ac98SMichael Ira Krufky 	0x0091, /* AICCVSYNC */
18236da7ac98SMichael Ira Krufky 	0x009C, /* CARRFREQOFFSET[15:8] */
18246da7ac98SMichael Ira Krufky 	0x009D, /* CARRFREQOFFSET[7:0] */
18256da7ac98SMichael Ira Krufky 	0x00A1, /* SAMFREQOFFSET[23:16] */
18266da7ac98SMichael Ira Krufky 	0x00A2, /* SAMFREQOFFSET[15:8] */
18276da7ac98SMichael Ira Krufky 	0x00A3, /* SAMFREQOFFSET[7:0] */
18286da7ac98SMichael Ira Krufky 	0x00A6, /* SYNCLOCK SYNCLOCKH */
18296da7ac98SMichael Ira Krufky #if 0 /* covered elsewhere */
18306da7ac98SMichael Ira Krufky 	0x00E8, /* CONSTPWR[15:8] */
18316da7ac98SMichael Ira Krufky 	0x00E9, /* CONSTPWR[7:0] */
18326da7ac98SMichael Ira Krufky 	0x00EA, /* BMSE[15:8] */
18336da7ac98SMichael Ira Krufky 	0x00EB, /* BMSE[7:0] */
18346da7ac98SMichael Ira Krufky 	0x00EC, /* MSE[15:8] */
18356da7ac98SMichael Ira Krufky 	0x00ED, /* MSE[7:0] */
18366da7ac98SMichael Ira Krufky 	0x00EE, /* CONSTI[7:0] */
18376da7ac98SMichael Ira Krufky 	0x00EF, /* CONSTQ[7:0] */
1838b63b36faSFred Richter #endif
18396da7ac98SMichael Ira Krufky 	0x00F4, /* TPIFTPERRCNT[7:0] */
18406da7ac98SMichael Ira Krufky 	0x00F5, /* TPCORREC */
18416da7ac98SMichael Ira Krufky 	0x00F6, /* VBBER[15:8] */
18426da7ac98SMichael Ira Krufky 	0x00F7, /* VBBER[7:0] */
18436da7ac98SMichael Ira Krufky 	0x00F8, /* VABER[15:8] */
18446da7ac98SMichael Ira Krufky 	0x00F9, /* VABER[7:0] */
18456da7ac98SMichael Ira Krufky 	0x00FA, /* TPERRCNT[7:0] */
18466da7ac98SMichael Ira Krufky 	0x00FB, /* NBERLOCK x x x x x x x */
18476da7ac98SMichael Ira Krufky 	0x00FC, /* NBERVALUE[31:24] */
18486da7ac98SMichael Ira Krufky 	0x00FD, /* NBERVALUE[23:16] */
18496da7ac98SMichael Ira Krufky 	0x00FE, /* NBERVALUE[15:8] */
18506da7ac98SMichael Ira Krufky 	0x00FF, /* NBERVALUE[7:0] */
18516da7ac98SMichael Ira Krufky 	0x1000, /* 1'b0 WODAGCOU */
18526da7ac98SMichael Ira Krufky 	0x1005, /* x x 1'b1 1'b1 x SRD_Q_QM */
18536da7ac98SMichael Ira Krufky 	0x1009, /* SRDWAITTIME[7:0] (10msec) 00100011 */
18546da7ac98SMichael Ira Krufky 	0x100A, /* SRDWAITTIME_CQS[7:0] (msec) 01100100 */
18556da7ac98SMichael Ira Krufky 	0x101A, /* x 1'b1 1'b0 1'b0 x QMDQAMMODE[2:0] x100x010 */
18566da7ac98SMichael Ira Krufky 	0x1036, /* 1'b0 1'b1 1'b0 1'b0 SAMGSEND_CQS[3:0] 01001110 */
18576da7ac98SMichael Ira Krufky 	0x103C, /* SAMGSAUTOSTL_V[3:0] SAMGSAUTOEDL_V[3:0] 01000110 */
18586da7ac98SMichael Ira Krufky 	0x103D, /* 1'b1 1'b1 SAMCNORMBP_V[1:0] 1'b0 1'b0 SAMMODESEL_V[1:0] 11100001 */
18596da7ac98SMichael Ira Krufky 	0x103F, /* SAMZTEDSE */
18606da7ac98SMichael Ira Krufky 	0x105D, /* EQSTATUSE */
18616da7ac98SMichael Ira Krufky 	0x105F, /* x PMAPG2_V[2:0] x DMAPG2_V[2:0] x001x011 */
18626da7ac98SMichael Ira Krufky 	0x1060, /* 1'b1 EQSTATUSE */
18636da7ac98SMichael Ira Krufky 	0x1061, /* CRMAPBWSTL_V[3:0] CRMAPBWEDL_V[3:0] 00000100 */
18646da7ac98SMichael Ira Krufky 	0x1065, /* 1'b0 x CRMODE_V[1:0] 1'b1 x 1'b1 x 0x111x1x */
18656da7ac98SMichael Ira Krufky 	0x1066, /* 1'b0 1'b0 1'b1 1'b0 1'b1 PNBOOSTSE */
18666da7ac98SMichael Ira Krufky 	0x1068, /* CREPHNGAIN2_V[3:0] CREPHNPBW_V[3:0] 10010001 */
18676da7ac98SMichael Ira Krufky 	0x106E, /* x x x x x CREPHNEN_ */
18686da7ac98SMichael Ira Krufky 	0x106F, /* CREPHNTH_V[7:0] 00010101 */
18696da7ac98SMichael Ira Krufky 	0x1072, /* CRSWEEPN */
18706da7ac98SMichael Ira Krufky 	0x1073, /* CRPGAIN_V[3:0] x x 1'b1 1'b1 1001xx11 */
18716da7ac98SMichael Ira Krufky 	0x1074, /* CRPBW_V[3:0] x x 1'b1 1'b1 0001xx11 */
18726da7ac98SMichael Ira Krufky 	0x1080, /* DAFTSTATUS[1:0] x x x x x x */
18736da7ac98SMichael Ira Krufky 	0x1081, /* SRDSTATUS[1:0] x x x x x SRDLOCK */
18746da7ac98SMichael Ira Krufky 	0x10A9, /* EQSTATUS_CQS[1:0] x x x x x x */
18756da7ac98SMichael Ira Krufky 	0x10B7, /* EQSTATUS_V[1:0] x x x x x x */
18766da7ac98SMichael Ira Krufky #if 0 /* SMART_ANT */
18776da7ac98SMichael Ira Krufky 	0x1F00, /* MODEDETE */
18786da7ac98SMichael Ira Krufky 	0x1F01, /* x x x x x x x SFNRST xxxxxxx0 */
18796da7ac98SMichael Ira Krufky 	0x1F03, /* NUMOFANT[7:0] 10000000 */
18806da7ac98SMichael Ira Krufky 	0x1F04, /* x SELMASK[6:0] x0000000 */
18816da7ac98SMichael Ira Krufky 	0x1F05, /* x SETMASK[6:0] x0000000 */
18826da7ac98SMichael Ira Krufky 	0x1F06, /* x TXDATA[6:0] x0000000 */
18836da7ac98SMichael Ira Krufky 	0x1F07, /* x CHNUMBER[6:0] x0000000 */
18846da7ac98SMichael Ira Krufky 	0x1F09, /* AGCTIME[23:16] 10011000 */
18856da7ac98SMichael Ira Krufky 	0x1F0A, /* AGCTIME[15:8] 10010110 */
18866da7ac98SMichael Ira Krufky 	0x1F0B, /* AGCTIME[7:0] 10000000 */
18876da7ac98SMichael Ira Krufky 	0x1F0C, /* ANTTIME[31:24] 00000000 */
18886da7ac98SMichael Ira Krufky 	0x1F0D, /* ANTTIME[23:16] 00000011 */
18896da7ac98SMichael Ira Krufky 	0x1F0E, /* ANTTIME[15:8] 10010000 */
18906da7ac98SMichael Ira Krufky 	0x1F0F, /* ANTTIME[7:0] 10010000 */
18916da7ac98SMichael Ira Krufky 	0x1F11, /* SYNCTIME[23:16] 10011000 */
18926da7ac98SMichael Ira Krufky 	0x1F12, /* SYNCTIME[15:8] 10010110 */
18936da7ac98SMichael Ira Krufky 	0x1F13, /* SYNCTIME[7:0] 10000000 */
18946da7ac98SMichael Ira Krufky 	0x1F14, /* SNRTIME[31:24] 00000001 */
18956da7ac98SMichael Ira Krufky 	0x1F15, /* SNRTIME[23:16] 01111101 */
18966da7ac98SMichael Ira Krufky 	0x1F16, /* SNRTIME[15:8] 01111000 */
18976da7ac98SMichael Ira Krufky 	0x1F17, /* SNRTIME[7:0] 01000000 */
18986da7ac98SMichael Ira Krufky 	0x1F19, /* FECTIME[23:16] 00000000 */
18996da7ac98SMichael Ira Krufky 	0x1F1A, /* FECTIME[15:8] 01110010 */
19006da7ac98SMichael Ira Krufky 	0x1F1B, /* FECTIME[7:0] 01110000 */
19016da7ac98SMichael Ira Krufky 	0x1F1D, /* FECTHD[7:0] 00000011 */
19026da7ac98SMichael Ira Krufky 	0x1F1F, /* SNRTHD[23:16] 00001000 */
19036da7ac98SMichael Ira Krufky 	0x1F20, /* SNRTHD[15:8] 01111111 */
19046da7ac98SMichael Ira Krufky 	0x1F21, /* SNRTHD[7:0] 10000101 */
19056da7ac98SMichael Ira Krufky 	0x1F80, /* IRQFLG x x SFSDRFLG MODEBFLG SAVEFLG SCANFLG TRACKFLG */
19066da7ac98SMichael Ira Krufky 	0x1F81, /* x SYNCCON SNRCON FECCON x STDBUSY SYNCRST AGCFZCO */
19076da7ac98SMichael Ira Krufky 	0x1F82, /* x x x SCANOPCD[4:0] */
19086da7ac98SMichael Ira Krufky 	0x1F83, /* x x x x MAINOPCD[3:0] */
19096da7ac98SMichael Ira Krufky 	0x1F84, /* x x RXDATA[13:8] */
19106da7ac98SMichael Ira Krufky 	0x1F85, /* RXDATA[7:0] */
19116da7ac98SMichael Ira Krufky 	0x1F86, /* x x SDTDATA[13:8] */
19126da7ac98SMichael Ira Krufky 	0x1F87, /* SDTDATA[7:0] */
19136da7ac98SMichael Ira Krufky 	0x1F89, /* ANTSNR[23:16] */
19146da7ac98SMichael Ira Krufky 	0x1F8A, /* ANTSNR[15:8] */
19156da7ac98SMichael Ira Krufky 	0x1F8B, /* ANTSNR[7:0] */
19166da7ac98SMichael Ira Krufky 	0x1F8C, /* x x x x ANTFEC[13:8] */
19176da7ac98SMichael Ira Krufky 	0x1F8D, /* ANTFEC[7:0] */
19186da7ac98SMichael Ira Krufky 	0x1F8E, /* MAXCNT[7:0] */
19196da7ac98SMichael Ira Krufky 	0x1F8F, /* SCANCNT[7:0] */
19206da7ac98SMichael Ira Krufky 	0x1F91, /* MAXPW[23:16] */
19216da7ac98SMichael Ira Krufky 	0x1F92, /* MAXPW[15:8] */
19226da7ac98SMichael Ira Krufky 	0x1F93, /* MAXPW[7:0] */
19236da7ac98SMichael Ira Krufky 	0x1F95, /* CURPWMSE[23:16] */
19246da7ac98SMichael Ira Krufky 	0x1F96, /* CURPWMSE[15:8] */
19256da7ac98SMichael Ira Krufky 	0x1F97, /* CURPWMSE[7:0] */
19266da7ac98SMichael Ira Krufky #endif /* SMART_ANT */
19276da7ac98SMichael Ira Krufky 	0x211F, /* 1'b1 1'b1 1'b1 CIRQEN x x 1'b0 1'b0 1111xx00 */
19286da7ac98SMichael Ira Krufky 	0x212A, /* EQAUTOST */
19296da7ac98SMichael Ira Krufky 	0x2122, /* CHFAST[7:0] 01100000 */
19306da7ac98SMichael Ira Krufky 	0x212B, /* FFFSTEP_V[3:0] x FBFSTEP_V[2:0] 0001x001 */
19316da7ac98SMichael Ira Krufky 	0x212C, /* PHDEROTBWSEL[3:0] 1'b1 1'b1 1'b1 1'b0 10001110 */
19326da7ac98SMichael Ira Krufky 	0x212D, /* 1'b1 1'b1 1'b1 1'b1 x x TPIFLOCKS */
19336da7ac98SMichael Ira Krufky 	0x2135, /* DYNTRACKFDEQ[3:0] x 1'b0 1'b0 1'b0 1010x000 */
19346da7ac98SMichael Ira Krufky 	0x2141, /* TRMODE[1:0] 1'b1 1'b1 1'b0 1'b1 1'b1 1'b1 01110111 */
19356da7ac98SMichael Ira Krufky 	0x2162, /* AICCCTRLE */
19366da7ac98SMichael Ira Krufky 	0x2173, /* PHNCNFCNT[7:0] 00000100 */
19376da7ac98SMichael Ira Krufky 	0x2179, /* 1'b0 1'b0 1'b0 1'b1 x BADSINGLEDYNTRACKFBF[2:0] 0001x001 */
19386da7ac98SMichael Ira Krufky 	0x217A, /* 1'b0 1'b0 1'b0 1'b1 x BADSLOWSINGLEDYNTRACKFBF[2:0] 0001x001 */
19396da7ac98SMichael Ira Krufky 	0x217E, /* CNFCNTTPIF[7:0] 00001000 */
19406da7ac98SMichael Ira Krufky 	0x217F, /* TPERRCNTTPIF[7:0] 00000001 */
19416da7ac98SMichael Ira Krufky 	0x2180, /* x x x x x x FBDLYCIR[9:8] */
19426da7ac98SMichael Ira Krufky 	0x2181, /* FBDLYCIR[7:0] */
19436da7ac98SMichael Ira Krufky 	0x2185, /* MAXPWRMAIN[7:0] */
19446da7ac98SMichael Ira Krufky 	0x2191, /* NCOMBDET x x x x x x x */
19456da7ac98SMichael Ira Krufky 	0x2199, /* x MAINSTRON */
19466da7ac98SMichael Ira Krufky 	0x219A, /* FFFEQSTEPOUT_V[3:0] FBFSTEPOUT_V[2:0] */
19476da7ac98SMichael Ira Krufky 	0x21A1, /* x x SNRREF[5:0] */
19486da7ac98SMichael Ira Krufky 	0x2845, /* 1'b0 1'b1 x x FFFSTEP_CQS[1:0] FFFCENTERTAP[1:0] 01xx1110 */
19496da7ac98SMichael Ira Krufky 	0x2846, /* 1'b0 x 1'b0 1'b1 FBFSTEP_CQS[1:0] 1'b1 1'b0 0x011110 */
19506da7ac98SMichael Ira Krufky 	0x2847, /* ENNOSIGDE */
19516da7ac98SMichael Ira Krufky 	0x2849, /* 1'b1 1'b1 NOUSENOSI */
19526da7ac98SMichael Ira Krufky 	0x284A, /* EQINITWAITTIME[7:0] 01100100 */
19536da7ac98SMichael Ira Krufky 	0x3000, /* 1'b1 1'b1 1'b1 x x x 1'b0 RPTRSTM */
19546da7ac98SMichael Ira Krufky 	0x3001, /* RPTRSTWAITTIME[7:0] (100msec) 00110010 */
19556da7ac98SMichael Ira Krufky 	0x3031, /* FRAMELOC */
19566da7ac98SMichael Ira Krufky 	0x3032, /* 1'b1 1'b0 1'b0 1'b0 x x FRAMELOCKMODE_CQS[1:0] 1000xx11 */
19576da7ac98SMichael Ira Krufky 	0x30A9, /* VDLOCK_Q FRAMELOCK */
19586da7ac98SMichael Ira Krufky 	0x30AA, /* MPEGLOCK */
1959b63b36faSFred Richter };
1960b63b36faSFred Richter 
1961b63b36faSFred Richter #define numDumpRegs  (sizeof(regtab)/sizeof(regtab[0]))
1962b63b36faSFred Richter static u8 regval1[numDumpRegs] = {0, };
1963b63b36faSFred Richter static u8 regval2[numDumpRegs] = {0, };
1964b63b36faSFred Richter 
1965b63b36faSFred Richter static void lgdt3306a_DumpAllRegs(struct lgdt3306a_state *state)
1966b63b36faSFred Richter {
1967b63b36faSFred Richter 		memset(regval2, 0xff, sizeof(regval2));
1968b63b36faSFred Richter 		lgdt3306a_DumpRegs(state);
1969b63b36faSFred Richter }
1970b63b36faSFred Richter 
1971b63b36faSFred Richter static void lgdt3306a_DumpRegs(struct lgdt3306a_state *state)
1972b63b36faSFred Richter {
1973b63b36faSFred Richter 	int i;
1974b63b36faSFred Richter 	int sav_debug = debug;
19758e8cd34eSMichael Ira Krufky 
1976b63b36faSFred Richter 	if ((debug & DBG_DUMP) == 0)
1977b63b36faSFred Richter 		return;
1978*831a9112SMichael Ira Krufky 	debug &= ~DBG_REG; /* suppress DBG_REG during reg dump */
1979b63b36faSFred Richter 
1980b63b36faSFred Richter 	lg_info("\n");
1981b63b36faSFred Richter 
1982b63b36faSFred Richter 	for (i = 0; i < numDumpRegs; i++) {
1983b63b36faSFred Richter 		lgdt3306a_read_reg(state, regtab[i], &regval1[i]);
1984b63b36faSFred Richter 		if (regval1[i] != regval2[i]) {
1985b63b36faSFred Richter 			lg_info(" %04X = %02X\n", regtab[i], regval1[i]);
1986b63b36faSFred Richter 				regval2[i] = regval1[i];
1987b63b36faSFred Richter 		}
1988b63b36faSFred Richter 	}
1989b63b36faSFred Richter 	debug = sav_debug;
1990b63b36faSFred Richter }
19918e8cd34eSMichael Ira Krufky #endif /* DBG_DUMP */
1992b63b36faSFred Richter 
1993b63b36faSFred Richter 
1994b63b36faSFred Richter 
1995b63b36faSFred Richter static struct dvb_frontend_ops lgdt3306a_ops = {
1996b63b36faSFred Richter 	.delsys = { SYS_ATSC, SYS_DVBC_ANNEX_B },
1997b63b36faSFred Richter 	.info = {
1998b63b36faSFred Richter 		.name = "LG Electronics LGDT3306A VSB/QAM Frontend",
19998e8cd34eSMichael Ira Krufky #if 0
20008e8cd34eSMichael Ira Krufky 		.type               = FE_ATSC,
20018e8cd34eSMichael Ira Krufky #endif
2002b63b36faSFred Richter 		.frequency_min      = 54000000,
20038e8cd34eSMichael Ira Krufky 		.frequency_max      = 858000000,
2004b63b36faSFred Richter 		.frequency_stepsize = 62500,
2005b63b36faSFred Richter 		.caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
2006b63b36faSFred Richter 	},
2007b63b36faSFred Richter 	.i2c_gate_ctrl        = lgdt3306a_i2c_gate_ctrl,
2008b63b36faSFred Richter 	.init                 = lgdt3306a_init,
2009b63b36faSFred Richter 	.sleep                = lgdt3306a_fe_sleep,
2010b63b36faSFred Richter 	/* if this is set, it overrides the default swzigzag */
2011b63b36faSFred Richter 	.tune                 = lgdt3306a_tune,
2012b63b36faSFred Richter 	.set_frontend         = lgdt3306a_set_parameters,
2013b63b36faSFred Richter 	.get_frontend         = lgdt3306a_get_frontend,
2014b63b36faSFred Richter 	.get_frontend_algo    = lgdt3306a_get_frontend_algo,
2015b63b36faSFred Richter 	.get_tune_settings    = lgdt3306a_get_tune_settings,
2016b63b36faSFred Richter 	.read_status          = lgdt3306a_read_status,
2017b63b36faSFred Richter 	.read_ber             = lgdt3306a_read_ber,
2018b63b36faSFred Richter 	.read_signal_strength = lgdt3306a_read_signal_strength,
2019b63b36faSFred Richter 	.read_snr             = lgdt3306a_read_snr,
2020b63b36faSFred Richter 	.read_ucblocks        = lgdt3306a_read_ucblocks,
2021b63b36faSFred Richter 	.release              = lgdt3306a_release,
2022b63b36faSFred Richter 	.ts_bus_ctrl          = lgdt3306a_ts_bus_ctrl,
2023b63b36faSFred Richter 	.search               = lgdt3306a_search,
2024b63b36faSFred Richter };
2025b63b36faSFred Richter 
2026b63b36faSFred Richter MODULE_DESCRIPTION("LG Electronics LGDT3306A ATSC/QAM-B Demodulator Driver");
2027b63b36faSFred Richter MODULE_AUTHOR("Fred Richter <frichter@hauppauge.com>");
2028b63b36faSFred Richter MODULE_LICENSE("GPL");
2029b63b36faSFred Richter MODULE_VERSION("0.2");
2030b63b36faSFred Richter 
2031b63b36faSFred Richter /*
2032b63b36faSFred Richter  * Local variables:
2033b63b36faSFred Richter  * c-basic-offset: 8
2034b63b36faSFred Richter  * End:
2035b63b36faSFred Richter  */
2036