aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb
diff options
context:
space:
mode:
authorSteven Toth <stoth@hauppauge.com>2008-04-18 20:34:00 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-04-24 13:09:42 -0400
commit265a6510629ab39f33ece43a857089dd37978184 (patch)
tree021773e15d68f7d99c571d723a48397ae9cf9ef5 /drivers/media/dvb
parentc8234ea37fb8b7a904223672edf36d269ea569a2 (diff)
V4L/DVB (7621): Add support for Hauppauge HVR950Q/HVR850/FusioHDTV7-USB
Including support for the AU0828 USB Bridge. Including support for the AU8522 ATSC/QAM Demodulator. Including support for the AU8522 ATSC/QAM Demodulator. Signed-off-by: Steven Toth <stoth@hauppauge.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/dvb')
-rw-r--r--drivers/media/dvb/frontends/Kconfig8
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/au8522.c448
-rw-r--r--drivers/media/dvb/frontends/au8522.h55
4 files changed, 512 insertions, 0 deletions
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 4284a3092c14..ae3659be323f 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -291,6 +291,14 @@ config DVB_S5H1409
291 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 291 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
292 to support this frontend. 292 to support this frontend.
293 293
294config DVB_AU8522
295 tristate "Auvitek AU8522 based"
296 depends on DVB_CORE && I2C
297 default m if DVB_FE_CUSTOMISE
298 help
299 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
300 to support this frontend.
301
294comment "Tuners/PLL support" 302comment "Tuners/PLL support"
295 depends on DVB_CORE 303 depends on DVB_CORE
296 304
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 129367886bcc..8e23a30ed3be 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -53,3 +53,4 @@ obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o
53obj-$(CONFIG_DVB_S5H1409) += s5h1409.o 53obj-$(CONFIG_DVB_S5H1409) += s5h1409.o
54obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o 54obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o
55obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o 55obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o
56obj-$(CONFIG_DVB_AU8522) += au8522.o
diff --git a/drivers/media/dvb/frontends/au8522.c b/drivers/media/dvb/frontends/au8522.c
new file mode 100644
index 000000000000..d3c44b95e240
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522.c
@@ -0,0 +1,448 @@
1/*
2 Auvitek AU8522 QAM/8VSB demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include "dvb_frontend.h"
29#include "dvb-pll.h"
30#include "au8522.h"
31
32struct au8522_state {
33
34 struct i2c_adapter* i2c;
35
36 /* configuration settings */
37 const struct au8522_config* config;
38
39 struct dvb_frontend frontend;
40
41 u32 current_frequency;
42 fe_modulation_t current_modulation;
43
44};
45
46static int debug = 0;
47#define dprintk if (debug) printk
48
49/* 16 bit registers, 8 bit values */
50static int au8522_writereg(struct au8522_state* state, u16 reg, u8 data)
51{
52 int ret;
53 u8 buf [] = { reg >> 8, reg & 0xff, data };
54
55 struct i2c_msg msg = { .addr = state->config->demod_address,
56 .flags = 0, .buf = buf, .len = 3 };
57
58 ret = i2c_transfer(state->i2c, &msg, 1);
59
60 if (ret != 1)
61 printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, "
62 "ret == %i)\n", __FUNCTION__, reg, data, ret);
63
64 return (ret != 1) ? -1 : 0;
65}
66
67static u8 au8522_readreg(struct au8522_state* state, u16 reg)
68{
69 int ret;
70 u8 b0 [] = { reg >> 8, reg & 0xff };
71 u8 b1 [] = { 0 };
72
73 struct i2c_msg msg [] = {
74 { .addr = state->config->demod_address, .flags = 0,
75 .buf = b0, .len = 2 },
76 { .addr = state->config->demod_address, .flags = I2C_M_RD,
77 .buf = b1, .len = 1 } };
78
79 ret = i2c_transfer(state->i2c, msg, 2);
80
81 if (ret != 2)
82 printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret);
83 return b1[0];
84}
85
86static int au8522_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
87{
88 struct au8522_state* state = fe->demodulator_priv;
89
90 dprintk("%s(%d)\n", __FUNCTION__, enable);
91
92 if (enable)
93 return au8522_writereg(state, 0x106, 1);
94 else
95 return au8522_writereg(state, 0x106, 0);
96}
97
98static int au8522_enable_modulation(struct dvb_frontend* fe,
99 fe_modulation_t m)
100{
101 struct au8522_state* state = fe->demodulator_priv;
102
103 dprintk("%s(0x%08x)\n", __FUNCTION__, m);
104
105 switch(m) {
106 case VSB_8:
107 dprintk("%s() VSB_8\n", __FUNCTION__);
108
109 //au8522_writereg(state, 0x410b, 0x84); // Serial
110
111 //au8522_writereg(state, 0x8090, 0x82);
112 au8522_writereg(state, 0x8090, 0x84);
113 au8522_writereg(state, 0x4092, 0x11);
114 au8522_writereg(state, 0x2005, 0x00);
115 au8522_writereg(state, 0x8091, 0x80);
116
117 au8522_writereg(state, 0x80a3, 0x0c);
118 au8522_writereg(state, 0x80a4, 0xe8);
119 au8522_writereg(state, 0x8081, 0xc4);
120 au8522_writereg(state, 0x80a5, 0x40);
121 au8522_writereg(state, 0x80a7, 0x40);
122 au8522_writereg(state, 0x80a6, 0x67);
123 au8522_writereg(state, 0x8262, 0x20);
124 au8522_writereg(state, 0x821c, 0x30);
125 au8522_writereg(state, 0x80d8, 0x1a);
126 au8522_writereg(state, 0x8227, 0xa0);
127 au8522_writereg(state, 0x8121, 0xff);
128 au8522_writereg(state, 0x80a8, 0xf0);
129 au8522_writereg(state, 0x80a9, 0x05);
130 au8522_writereg(state, 0x80aa, 0x77);
131 au8522_writereg(state, 0x80ab, 0xf0);
132 au8522_writereg(state, 0x80ac, 0x05);
133 au8522_writereg(state, 0x80ad, 0x77);
134 au8522_writereg(state, 0x80ae, 0x41);
135 au8522_writereg(state, 0x80af, 0x66);
136 au8522_writereg(state, 0x821b, 0xcc);
137 au8522_writereg(state, 0x821d, 0x80);
138 au8522_writereg(state, 0x80b5, 0xfb);
139 au8522_writereg(state, 0x80b6, 0x8e);
140 au8522_writereg(state, 0x80b7, 0x39);
141 au8522_writereg(state, 0x80a4, 0xe8);
142 au8522_writereg(state, 0x8231, 0x13);
143 break;
144 case QAM_64:
145 case QAM_256:
146 au8522_writereg(state, 0x80a3, 0x09);
147 au8522_writereg(state, 0x80a4, 0x00);
148 au8522_writereg(state, 0x8081, 0xc4);
149 au8522_writereg(state, 0x80a5, 0x40);
150 au8522_writereg(state, 0x80b5, 0xfb);
151 au8522_writereg(state, 0x80b6, 0x8e);
152 au8522_writereg(state, 0x80b7, 0x39);
153 au8522_writereg(state, 0x80aa, 0x77);
154 au8522_writereg(state, 0x80ad, 0x77);
155 au8522_writereg(state, 0x80a6, 0x67);
156 au8522_writereg(state, 0x8262, 0x20);
157 au8522_writereg(state, 0x821c, 0x30);
158 au8522_writereg(state, 0x80b8, 0x3e);
159 au8522_writereg(state, 0x80b9, 0xf0);
160 au8522_writereg(state, 0x80ba, 0x01);
161 au8522_writereg(state, 0x80bb, 0x18);
162 au8522_writereg(state, 0x80bc, 0x50);
163 au8522_writereg(state, 0x80bd, 0x00);
164 au8522_writereg(state, 0x80be, 0xea);
165 au8522_writereg(state, 0x80bf, 0xef);
166 au8522_writereg(state, 0x80c0, 0xfc);
167 au8522_writereg(state, 0x80c1, 0xbd);
168 au8522_writereg(state, 0x80c2, 0x1f);
169 au8522_writereg(state, 0x80c3, 0xfc);
170 au8522_writereg(state, 0x80c4, 0xdd);
171 au8522_writereg(state, 0x80c5, 0xaf);
172 au8522_writereg(state, 0x80c6, 0x00);
173 au8522_writereg(state, 0x80c7, 0x38);
174 au8522_writereg(state, 0x80c8, 0x30);
175 au8522_writereg(state, 0x80c9, 0x05);
176 au8522_writereg(state, 0x80ca, 0x4a);
177 au8522_writereg(state, 0x80cb, 0xd0);
178 au8522_writereg(state, 0x80cc, 0x01);
179 au8522_writereg(state, 0x80cd, 0xd9);
180 au8522_writereg(state, 0x80ce, 0x6f);
181 au8522_writereg(state, 0x80cf, 0xf9);
182 au8522_writereg(state, 0x80d0, 0x70);
183 au8522_writereg(state, 0x80d1, 0xdf);
184 au8522_writereg(state, 0x80d2, 0xf7);
185 au8522_writereg(state, 0x80d3, 0xc2);
186 au8522_writereg(state, 0x80d4, 0xdf);
187 au8522_writereg(state, 0x80d5, 0x02);
188 au8522_writereg(state, 0x80d6, 0x9a);
189 au8522_writereg(state, 0x80d7, 0xd0);
190 au8522_writereg(state, 0x8250, 0x0d);
191 au8522_writereg(state, 0x8251, 0xcd);
192 au8522_writereg(state, 0x8252, 0xe0);
193 au8522_writereg(state, 0x8253, 0x05);
194 au8522_writereg(state, 0x8254, 0xa7);
195 au8522_writereg(state, 0x8255, 0xff);
196 au8522_writereg(state, 0x8256, 0xed);
197 au8522_writereg(state, 0x8257, 0x5b);
198 au8522_writereg(state, 0x8258, 0xae);
199 au8522_writereg(state, 0x8259, 0xe6);
200 au8522_writereg(state, 0x825a, 0x3d);
201 au8522_writereg(state, 0x825b, 0x0f);
202 au8522_writereg(state, 0x825c, 0x0d);
203 au8522_writereg(state, 0x825d, 0xea);
204 au8522_writereg(state, 0x825e, 0xf2);
205 au8522_writereg(state, 0x825f, 0x51);
206 au8522_writereg(state, 0x8260, 0xf5);
207 au8522_writereg(state, 0x8261, 0x06);
208 au8522_writereg(state, 0x821a, 0x00);
209 au8522_writereg(state, 0x8546, 0x40);
210 au8522_writereg(state, 0x8210, 0x26);
211 au8522_writereg(state, 0x8211, 0xf6);
212 au8522_writereg(state, 0x8212, 0x84);
213 au8522_writereg(state, 0x8213, 0x02);
214 au8522_writereg(state, 0x8502, 0x01);
215 au8522_writereg(state, 0x8121, 0x04);
216 au8522_writereg(state, 0x8122, 0x04);
217 au8522_writereg(state, 0x852e, 0x10);
218 au8522_writereg(state, 0x80a4, 0xca);
219 au8522_writereg(state, 0x80a7, 0x40);
220 au8522_writereg(state, 0x8526, 0x01);
221 break;
222 default:
223 dprintk("%s() Invalid modulation\n", __FUNCTION__);
224 return -EINVAL;
225 }
226
227 state->current_modulation = m;
228
229 return 0;
230}
231
232/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
233static int au8522_set_frontend (struct dvb_frontend* fe,
234 struct dvb_frontend_parameters *p)
235{
236 struct au8522_state* state = fe->demodulator_priv;
237
238 dprintk("%s(frequency=%d)\n", __FUNCTION__, p->frequency);
239
240 state->current_frequency = p->frequency;
241
242 au8522_enable_modulation(fe, p->u.vsb.modulation);
243
244 /* Allow the demod to settle */
245 msleep(100);
246
247 if (fe->ops.tuner_ops.set_params) {
248 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 1);
249 fe->ops.tuner_ops.set_params(fe, p);
250 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0);
251 }
252
253 return 0;
254}
255
256/* Reset the demod hardware and reset all of the configuration registers
257 to a default state. */
258static int au8522_init(struct dvb_frontend* fe)
259{
260 struct au8522_state* state = fe->demodulator_priv;
261 dprintk("%s()\n", __FUNCTION__);
262
263 au8522_writereg(state, 0xa4, 1 << 5);
264
265 au8522_i2c_gate_ctrl(fe, 1);
266
267 return 0;
268}
269
270static int au8522_read_status(struct dvb_frontend* fe, fe_status_t* status)
271{
272 struct au8522_state* state = fe->demodulator_priv;
273 u8 reg;
274 u32 tuner_status = 0;
275
276 *status = 0;
277
278 if (state->current_modulation == VSB_8) {
279 dprintk("%s() Checking VSB_8\n", __FUNCTION__);
280 //au8522_writereg(state, 0x80a4, 0x20);
281 reg = au8522_readreg(state, 0x4088);
282 if(reg & 0x01)
283 *status |= FE_HAS_VITERBI;
284 if(reg & 0x02)
285 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
286 } else {
287 dprintk("%s() Checking QAM\n", __FUNCTION__);
288 reg = au8522_readreg(state, 0x4541);
289 if(reg & 0x80)
290 *status |= FE_HAS_VITERBI;
291 if(reg & 0x20)
292 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
293 }
294
295 switch(state->config->status_mode) {
296 case AU8522_DEMODLOCKING:
297 dprintk("%s() DEMODLOCKING\n", __FUNCTION__);
298 if (*status & FE_HAS_VITERBI)
299 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
300 break;
301 case AU8522_TUNERLOCKING:
302 /* Get the tuner status */
303 dprintk("%s() TUNERLOCKING\n", __FUNCTION__);
304 if (fe->ops.tuner_ops.get_status) {
305 if (fe->ops.i2c_gate_ctrl)
306 fe->ops.i2c_gate_ctrl(fe, 1);
307
308 fe->ops.tuner_ops.get_status(fe, &tuner_status);
309
310 if (fe->ops.i2c_gate_ctrl)
311 fe->ops.i2c_gate_ctrl(fe, 0);
312 }
313 if (tuner_status)
314 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
315 break;
316 }
317
318 dprintk("%s() status 0x%08x\n", __FUNCTION__, *status);
319
320 return 0;
321}
322
323static int au8522_read_snr(struct dvb_frontend* fe, u16* snr)
324{
325 dprintk("%s()\n", __FUNCTION__);
326
327 *snr = 0;
328
329 return 0;
330}
331
332static int au8522_read_signal_strength(struct dvb_frontend* fe,
333 u16* signal_strength)
334{
335 return au8522_read_snr(fe, signal_strength);
336}
337
338static int au8522_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
339{
340 struct au8522_state* state = fe->demodulator_priv;
341
342 *ucblocks = au8522_readreg(state, 0x4087);
343
344 return 0;
345}
346
347static int au8522_read_ber(struct dvb_frontend* fe, u32* ber)
348{
349 return au8522_read_ucblocks(fe, ber);
350}
351
352static int au8522_get_frontend(struct dvb_frontend* fe,
353 struct dvb_frontend_parameters *p)
354{
355 struct au8522_state* state = fe->demodulator_priv;
356
357 p->frequency = state->current_frequency;
358 p->u.vsb.modulation = state->current_modulation;
359
360 return 0;
361}
362
363static int au8522_get_tune_settings(struct dvb_frontend* fe,
364 struct dvb_frontend_tune_settings *tune)
365{
366 tune->min_delay_ms = 1000;
367 return 0;
368}
369
370static void au8522_release(struct dvb_frontend* fe)
371{
372 struct au8522_state* state = fe->demodulator_priv;
373 kfree(state);
374}
375
376static struct dvb_frontend_ops au8522_ops;
377
378struct dvb_frontend* au8522_attach(const struct au8522_config* config,
379 struct i2c_adapter* i2c)
380{
381 struct au8522_state* state = NULL;
382
383 /* allocate memory for the internal state */
384 state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL);
385 if (state == NULL)
386 goto error;
387
388 /* setup the state */
389 state->config = config;
390 state->i2c = i2c;
391 /* create dvb_frontend */
392 memcpy(&state->frontend.ops, &au8522_ops,
393 sizeof(struct dvb_frontend_ops));
394 state->frontend.demodulator_priv = state;
395
396 if (au8522_init(&state->frontend) != 0) {
397 printk(KERN_ERR "%s: Failed to initialize correctly\n",
398 __FUNCTION__);
399 goto error;
400 }
401
402 /* Note: Leaving the I2C gate open here. */
403 au8522_i2c_gate_ctrl(&state->frontend, 1);
404
405 return &state->frontend;
406
407error:
408 kfree(state);
409 return NULL;
410}
411
412static struct dvb_frontend_ops au8522_ops = {
413
414 .info = {
415 .name = "Auvitek AU8522 QAM/8VSB Frontend",
416 .type = FE_ATSC,
417 .frequency_min = 54000000,
418 .frequency_max = 858000000,
419 .frequency_stepsize = 62500,
420 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
421 },
422
423 .init = au8522_init,
424 .i2c_gate_ctrl = au8522_i2c_gate_ctrl,
425 .set_frontend = au8522_set_frontend,
426 .get_frontend = au8522_get_frontend,
427 .get_tune_settings = au8522_get_tune_settings,
428 .read_status = au8522_read_status,
429 .read_ber = au8522_read_ber,
430 .read_signal_strength = au8522_read_signal_strength,
431 .read_snr = au8522_read_snr,
432 .read_ucblocks = au8522_read_ucblocks,
433 .release = au8522_release,
434};
435
436module_param(debug, int, 0644);
437MODULE_PARM_DESC(debug, "Enable verbose debug messages");
438
439MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver");
440MODULE_AUTHOR("Steven Toth");
441MODULE_LICENSE("GPL");
442
443EXPORT_SYMBOL(au8522_attach);
444
445/*
446 * Local variables:
447 * c-basic-offset: 8
448 */
diff --git a/drivers/media/dvb/frontends/au8522.h b/drivers/media/dvb/frontends/au8522.h
new file mode 100644
index 000000000000..a75627155fed
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522.h
@@ -0,0 +1,55 @@
1/*
2 Auvitek AU8522 QAM/8VSB demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#ifndef __AU8522_H__
23#define __AU8522_H__
24
25#include <linux/dvb/frontend.h>
26
27struct au8522_config
28{
29 /* the demodulator's i2c address */
30 u8 demod_address;
31
32 /* Return lock status based on tuner lock, or demod lock */
33#define AU8522_TUNERLOCKING 0
34#define AU8522_DEMODLOCKING 1
35 u8 status_mode;
36};
37
38#if defined(CONFIG_DVB_AU8522) || (defined(CONFIG_DVB_AU8522_MODULE) && defined(MODULE))
39extern struct dvb_frontend* au8522_attach(const struct au8522_config* config,
40 struct i2c_adapter* i2c);
41#else
42static inline struct dvb_frontend* au8522_attach(const struct au8522_config* config,
43 struct i2c_adapter* i2c)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
46 return NULL;
47}
48#endif /* CONFIG_DVB_AU8522 */
49
50#endif /* __AU8522_H__ */
51
52/*
53 * Local variables:
54 * c-basic-offset: 8
55 */