2 * av7110_v4l.c: av7110 video4linux interface for DVB and Siemens DVB-C analog module
4 * Copyright (C) 1999-2002 Ralph Metzler
5 * & Marcus Metzler for convergence integrated media GmbH
7 * originally based on code by:
8 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
25 * the project's page is at http://www.linuxtv.org/
28 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30 #include <linux/kernel.h>
31 #include <linux/types.h>
32 #include <linux/delay.h>
34 #include <linux/timer.h>
35 #include <linux/poll.h>
38 #include "av7110_hw.h"
39 #include "av7110_av.h"
41 int msp_writereg(struct av7110 *av7110, u8 dev, u16 reg, u16 val)
43 u8 msg[5] = { dev, reg >> 8, reg & 0xff, val >> 8 , val & 0xff };
44 struct i2c_msg msgs = { .flags = 0, .len = 5, .buf = msg };
46 switch (av7110->adac_type) {
47 case DVB_ADAC_MSP34x0:
50 case DVB_ADAC_MSP34x5:
57 if (i2c_transfer(&av7110->i2c_adap, &msgs, 1) != 1) {
58 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
59 av7110->dvb_adapter.num, reg, val);
65 static int msp_readreg(struct av7110 *av7110, u8 dev, u16 reg, u16 *val)
67 u8 msg1[3] = { dev, reg >> 8, reg & 0xff };
69 struct i2c_msg msgs[2] = {
70 { .flags = 0 , .len = 3, .buf = msg1 },
71 { .flags = I2C_M_RD, .len = 2, .buf = msg2 }
74 switch (av7110->adac_type) {
75 case DVB_ADAC_MSP34x0:
79 case DVB_ADAC_MSP34x5:
87 if (i2c_transfer(&av7110->i2c_adap, &msgs[0], 2) != 2) {
88 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
89 av7110->dvb_adapter.num, reg);
92 *val = (msg2[0] << 8) | msg2[1];
96 static struct v4l2_input inputs[4] = {
100 .type = V4L2_INPUT_TYPE_CAMERA,
102 .tuner = 0, /* ignored */
103 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
105 .capabilities = V4L2_IN_CAP_STD,
108 .name = "Television",
109 .type = V4L2_INPUT_TYPE_TUNER,
112 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
114 .capabilities = V4L2_IN_CAP_STD,
118 .type = V4L2_INPUT_TYPE_CAMERA,
121 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
123 .capabilities = V4L2_IN_CAP_STD,
127 .type = V4L2_INPUT_TYPE_CAMERA,
130 .std = V4L2_STD_PAL_BG|V4L2_STD_NTSC_M,
132 .capabilities = V4L2_IN_CAP_STD,
136 static int ves1820_writereg(struct saa7146_dev *dev, u8 addr, u8 reg, u8 data)
138 struct av7110 *av7110 = dev->ext_priv;
139 u8 buf[] = { 0x00, reg, data };
140 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = buf, .len = 3 };
142 dprintk(4, "dev: %p\n", dev);
144 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
149 static int tuner_write(struct saa7146_dev *dev, u8 addr, u8 data [4])
151 struct av7110 *av7110 = dev->ext_priv;
152 struct i2c_msg msg = { .addr = addr, .flags = 0, .buf = data, .len = 4 };
154 dprintk(4, "dev: %p\n", dev);
156 if (1 != i2c_transfer(&av7110->i2c_adap, &msg, 1))
161 static int ves1820_set_tv_freq(struct saa7146_dev *dev, u32 freq)
167 dprintk(4, "freq: 0x%08x\n", freq);
169 /* magic number: 614. tuning with the frequency given by v4l2
170 is always off by 614*62.5 = 38375 kHz...*/
173 buf[0] = (div >> 8) & 0x7f;
177 if (freq < (u32) (16 * 168.25))
179 else if (freq < (u32) (16 * 447.25))
187 return tuner_write(dev, 0x61, buf);
190 static int stv0297_set_tv_freq(struct saa7146_dev *dev, u32 freq)
192 struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
196 div = (freq + 38900000 + 31250) / 62500;
198 data[0] = (div >> 8) & 0x7f;
199 data[1] = div & 0xff;
204 else if (freq < 137000000)
206 else if (freq < 403000000)
208 else if (freq < 860000000)
213 if (av7110->fe->ops.i2c_gate_ctrl)
214 av7110->fe->ops.i2c_gate_ctrl(av7110->fe, 1);
215 return tuner_write(dev, 0x63, data);
220 static struct saa7146_standard analog_standard[];
221 static struct saa7146_standard dvb_standard[];
222 static struct saa7146_standard standard[];
224 static struct v4l2_audio msp3400_v4l2_audio = {
226 .name = "Television",
227 .capability = V4L2_AUDCAP_STEREO
230 static int av7110_dvb_c_switch(struct saa7146_fh *fh)
232 struct saa7146_dev *dev = fh->dev;
233 struct saa7146_vv *vv = dev->vv_data;
234 struct av7110 *av7110 = (struct av7110*)dev->ext_priv;
236 int source, sync, err;
238 dprintk(4, "%p\n", av7110);
240 if ((vv->video_status & STATUS_OVERLAY) != 0) {
241 vv->ov_suspend = vv->video_fh;
242 err = saa7146_stop_preview(vv->video_fh); /* side effect: video_status is now 0, video_fh is NULL */
244 dprintk(2, "suspending video failed\n");
245 vv->ov_suspend = NULL;
249 if (0 != av7110->current_input) {
250 dprintk(1, "switching to analog TV:\n");
252 source = SAA7146_HPS_SOURCE_PORT_B;
253 sync = SAA7146_HPS_SYNC_PORT_B;
254 memcpy(standard, analog_standard, sizeof(struct saa7146_standard) * 2);
256 switch (av7110->current_input) {
258 dprintk(1, "switching SAA7113 to Analog Tuner Input\n");
259 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0000); // loudspeaker source
260 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0000); // headphone source
261 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0000); // SCART 1 source
262 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
263 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); // loudspeaker + headphone
264 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); // SCART 1 volume
266 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
267 if (ves1820_writereg(dev, 0x09, 0x0f, 0x60))
268 dprintk(1, "setting band in demodulator failed\n");
269 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
270 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTHI); // TDA9819 pin9(STD)
271 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTHI); // TDA9819 pin30(VIF)
273 if (i2c_writereg(av7110, 0x48, 0x02, 0xd0) != 1)
274 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
277 dprintk(1, "switching SAA7113 to Video AV CVBS Input\n");
278 if (i2c_writereg(av7110, 0x48, 0x02, 0xd2) != 1)
279 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
282 dprintk(1, "switching SAA7113 to Video AV Y/C Input\n");
283 if (i2c_writereg(av7110, 0x48, 0x02, 0xd9) != 1)
284 dprintk(1, "saa7113 write failed @ card %d", av7110->dvb_adapter.num);
287 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input\n");
291 source = SAA7146_HPS_SOURCE_PORT_A;
292 sync = SAA7146_HPS_SYNC_PORT_A;
293 memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
294 dprintk(1, "switching DVB mode\n");
295 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
296 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
297 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
298 msp_writereg(av7110, MSP_WR_DSP, 0x000e, 0x3000); // FM matrix, mono
299 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
300 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
302 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
303 if (ves1820_writereg(dev, 0x09, 0x0f, 0x20))
304 dprintk(1, "setting band in demodulator failed\n");
305 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
306 saa7146_setgpio(dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
307 saa7146_setgpio(dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
311 /* hmm, this does not do anything!? */
312 if (av7110_fw_cmd(av7110, COMTYPE_AUDIODAC, ADSwitch, 1, adswitch))
313 dprintk(1, "ADSwitch error\n");
315 saa7146_set_hps_source_and_sync(dev, source, sync);
317 if (vv->ov_suspend != NULL) {
318 saa7146_start_preview(vv->ov_suspend);
319 vv->ov_suspend = NULL;
325 static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
327 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
328 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
332 dprintk(2, "VIDIOC_G_TUNER: %d\n", t->index);
334 if (!av7110->analog_tuner_flags || t->index != 0)
337 memset(t, 0, sizeof(*t));
338 strcpy((char *)t->name, "Television");
340 t->type = V4L2_TUNER_ANALOG_TV;
341 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
342 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
343 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
344 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
345 /* FIXME: add the real signal strength here */
349 /* FIXME: standard / stereo detection is still broken */
350 msp_readreg(av7110, MSP_RD_DEM, 0x007e, &stereo_det);
351 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det);
352 msp_readreg(av7110, MSP_RD_DSP, 0x0018, &stereo_det);
353 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det);
354 stereo = (s8)(stereo_det >> 8);
357 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
358 t->audmode = V4L2_TUNER_MODE_STEREO;
359 } else if (stereo < -0x10) {
361 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
362 t->audmode = V4L2_TUNER_MODE_LANG1;
364 t->rxsubchans = V4L2_TUNER_SUB_MONO;
369 static int vidioc_s_tuner(struct file *file, void *fh, struct v4l2_tuner *t)
371 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
372 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
374 dprintk(2, "VIDIOC_S_TUNER: %d\n", t->index);
376 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
379 switch (t->audmode) {
380 case V4L2_TUNER_MODE_STEREO:
381 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
382 fm_matrix = 0x3001; /* stereo */
385 case V4L2_TUNER_MODE_LANG1_LANG2:
386 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
387 fm_matrix = 0x3000; /* bilingual */
390 case V4L2_TUNER_MODE_LANG1:
391 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
392 fm_matrix = 0x3000; /* mono */
395 case V4L2_TUNER_MODE_LANG2:
396 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
397 fm_matrix = 0x3000; /* mono */
400 default: /* case V4L2_TUNER_MODE_MONO: */
401 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
402 fm_matrix = 0x3000; /* mono */
406 msp_writereg(av7110, MSP_WR_DSP, 0x000e, fm_matrix);
407 msp_writereg(av7110, MSP_WR_DSP, 0x0008, src);
408 msp_writereg(av7110, MSP_WR_DSP, 0x0009, src);
409 msp_writereg(av7110, MSP_WR_DSP, 0x000a, src);
413 static int vidioc_g_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
415 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
416 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
418 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x\n", f->frequency);
420 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
423 memset(f, 0, sizeof(*f));
424 f->type = V4L2_TUNER_ANALOG_TV;
425 f->frequency = av7110->current_freq;
429 static int vidioc_s_frequency(struct file *file, void *fh, struct v4l2_frequency *f)
431 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
432 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
434 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x\n", f->frequency);
436 if (!av7110->analog_tuner_flags || av7110->current_input != 1)
439 if (V4L2_TUNER_ANALOG_TV != f->type)
442 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0xffe0); /* fast mute */
443 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0xffe0);
445 /* tune in desired frequency */
446 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820)
447 ves1820_set_tv_freq(dev, f->frequency);
448 else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297)
449 stv0297_set_tv_freq(dev, f->frequency);
450 av7110->current_freq = f->frequency;
452 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x003f); /* start stereo detection */
453 msp_writereg(av7110, MSP_WR_DSP, 0x0015, 0x0000);
454 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x4f00); /* loudspeaker + headphone */
455 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x4f00); /* SCART 1 volume */
459 static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
461 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
462 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
464 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i->index);
466 if (av7110->analog_tuner_flags) {
474 memcpy(i, &inputs[i->index], sizeof(struct v4l2_input));
479 static int vidioc_g_input(struct file *file, void *fh, unsigned int *input)
481 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
482 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
484 *input = av7110->current_input;
485 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input);
489 static int vidioc_s_input(struct file *file, void *fh, unsigned int input)
491 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
492 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
494 dprintk(2, "VIDIOC_S_INPUT: %d\n", input);
496 if (!av7110->analog_tuner_flags)
502 av7110->current_input = input;
503 return av7110_dvb_c_switch(fh);
506 static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
508 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a->index);
511 memcpy(a, &msp3400_v4l2_audio, sizeof(struct v4l2_audio));
515 static int vidioc_s_audio(struct file *file, void *fh, struct v4l2_audio *a)
517 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a->index);
521 static int vidioc_g_sliced_vbi_cap(struct file *file, void *fh,
522 struct v4l2_sliced_vbi_cap *cap)
524 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
525 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
527 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
528 if (cap->type != V4L2_BUF_TYPE_SLICED_VBI_OUTPUT)
530 if (FW_VERSION(av7110->arm_app) >= 0x2623) {
531 cap->service_set = V4L2_SLICED_WSS_625;
532 cap->service_lines[0][23] = V4L2_SLICED_WSS_625;
537 static int vidioc_g_fmt_sliced_vbi_out(struct file *file, void *fh,
538 struct v4l2_format *f)
540 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
541 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
543 dprintk(2, "VIDIOC_G_FMT:\n");
544 if (FW_VERSION(av7110->arm_app) < 0x2623)
546 memset(&f->fmt.sliced, 0, sizeof f->fmt.sliced);
547 if (av7110->wssMode) {
548 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
549 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
550 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
555 static int vidioc_s_fmt_sliced_vbi_out(struct file *file, void *fh,
556 struct v4l2_format *f)
558 struct saa7146_dev *dev = ((struct saa7146_fh *)fh)->dev;
559 struct av7110 *av7110 = (struct av7110 *)dev->ext_priv;
561 dprintk(2, "VIDIOC_S_FMT\n");
562 if (FW_VERSION(av7110->arm_app) < 0x2623)
564 if (f->fmt.sliced.service_set != V4L2_SLICED_WSS_625 &&
565 f->fmt.sliced.service_lines[0][23] != V4L2_SLICED_WSS_625) {
566 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
567 /* WSS controlled by firmware */
570 return av7110_fw_cmd(av7110, COMTYPE_ENCODER,
573 memset(&f->fmt.sliced, 0, sizeof(f->fmt.sliced));
574 f->fmt.sliced.service_set = V4L2_SLICED_WSS_625;
575 f->fmt.sliced.service_lines[0][23] = V4L2_SLICED_WSS_625;
576 f->fmt.sliced.io_size = sizeof(struct v4l2_sliced_vbi_data);
577 /* WSS controlled by userspace */
584 static int av7110_vbi_reset(struct file *file)
586 struct saa7146_fh *fh = file->private_data;
587 struct saa7146_dev *dev = fh->dev;
588 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
590 dprintk(2, "%s\n", __func__);
593 if (FW_VERSION(av7110->arm_app) < 0x2623)
596 return av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 1, 0);
599 static ssize_t av7110_vbi_write(struct file *file, const char __user *data, size_t count, loff_t *ppos)
601 struct saa7146_fh *fh = file->private_data;
602 struct saa7146_dev *dev = fh->dev;
603 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
604 struct v4l2_sliced_vbi_data d;
607 dprintk(2, "%s\n", __func__);
608 if (FW_VERSION(av7110->arm_app) < 0x2623 || !av7110->wssMode || count != sizeof d)
610 if (copy_from_user(&d, data, count))
612 if ((d.id != 0 && d.id != V4L2_SLICED_WSS_625) || d.field != 0 || d.line != 23)
615 av7110->wssData = ((d.data[1] << 8) & 0x3f00) | d.data[0];
617 av7110->wssData = 0x8000;
618 rc = av7110_fw_cmd(av7110, COMTYPE_ENCODER, SetWSSConfig, 2, 1, av7110->wssData);
619 return (rc < 0) ? rc : count;
622 /****************************************************************************
624 ****************************************************************************/
626 static u8 saa7113_init_regs[] = {
685 static struct saa7146_ext_vv av7110_vv_data_st;
686 static struct saa7146_ext_vv av7110_vv_data_c;
688 int av7110_init_analog_module(struct av7110 *av7110)
690 u16 version1, version2;
692 if (i2c_writereg(av7110, 0x80, 0x0, 0x80) == 1 &&
693 i2c_writereg(av7110, 0x80, 0x0, 0) == 1) {
694 pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
695 av7110->dvb_adapter.num);
696 av7110->adac_type = DVB_ADAC_MSP34x0;
697 } else if (i2c_writereg(av7110, 0x84, 0x0, 0x80) == 1 &&
698 i2c_writereg(av7110, 0x84, 0x0, 0) == 1) {
699 pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
700 av7110->dvb_adapter.num);
701 av7110->adac_type = DVB_ADAC_MSP34x5;
705 msleep(100); // the probing above resets the msp...
706 msp_readreg(av7110, MSP_RD_DSP, 0x001e, &version1);
707 msp_readreg(av7110, MSP_RD_DSP, 0x001f, &version2);
708 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
709 av7110->dvb_adapter.num, version1, version2);
710 msp_writereg(av7110, MSP_WR_DSP, 0x0013, 0x0c00);
711 msp_writereg(av7110, MSP_WR_DSP, 0x0000, 0x7f00); // loudspeaker + headphone
712 msp_writereg(av7110, MSP_WR_DSP, 0x0008, 0x0220); // loudspeaker source
713 msp_writereg(av7110, MSP_WR_DSP, 0x0009, 0x0220); // headphone source
714 msp_writereg(av7110, MSP_WR_DSP, 0x0004, 0x7f00); // loudspeaker volume
715 msp_writereg(av7110, MSP_WR_DSP, 0x000a, 0x0220); // SCART 1 source
716 msp_writereg(av7110, MSP_WR_DSP, 0x0007, 0x7f00); // SCART 1 volume
717 msp_writereg(av7110, MSP_WR_DSP, 0x000d, 0x1900); // prescale SCART
719 if (i2c_writereg(av7110, 0x48, 0x01, 0x00)!=1) {
720 pr_info("saa7113 not accessible\n");
722 u8 *i = saa7113_init_regs;
724 if ((av7110->dev->pci->subsystem_vendor == 0x110a) && (av7110->dev->pci->subsystem_device == 0x0000)) {
725 /* Fujitsu/Siemens DVB-Cable */
726 av7110->analog_tuner_flags |= ANALOG_TUNER_VES1820;
727 } else if ((av7110->dev->pci->subsystem_vendor == 0x13c2) && (av7110->dev->pci->subsystem_device == 0x0002)) {
728 /* Hauppauge/TT DVB-C premium */
729 av7110->analog_tuner_flags |= ANALOG_TUNER_VES1820;
730 } else if ((av7110->dev->pci->subsystem_vendor == 0x13c2) && (av7110->dev->pci->subsystem_device == 0x000A)) {
731 /* Hauppauge/TT DVB-C premium */
732 av7110->analog_tuner_flags |= ANALOG_TUNER_STV0297;
735 /* setup for DVB by default */
736 if (av7110->analog_tuner_flags & ANALOG_TUNER_VES1820) {
737 if (ves1820_writereg(av7110->dev, 0x09, 0x0f, 0x20))
738 dprintk(1, "setting band in demodulator failed\n");
739 } else if (av7110->analog_tuner_flags & ANALOG_TUNER_STV0297) {
740 saa7146_setgpio(av7110->dev, 1, SAA7146_GPIO_OUTLO); // TDA9819 pin9(STD)
741 saa7146_setgpio(av7110->dev, 3, SAA7146_GPIO_OUTLO); // TDA9819 pin30(VIF)
744 /* init the saa7113 */
746 if (i2c_writereg(av7110, 0x48, i[0], i[1]) != 1) {
747 dprintk(1, "saa7113 initialization failed @ card %d", av7110->dvb_adapter.num);
752 /* setup msp for analog sound: B/G Dual-FM */
753 msp_writereg(av7110, MSP_WR_DEM, 0x00bb, 0x02d0); // AD_CV
754 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 3); // FIR1
755 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 18); // FIR1
756 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 27); // FIR1
757 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 48); // FIR1
758 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 66); // FIR1
759 msp_writereg(av7110, MSP_WR_DEM, 0x0001, 72); // FIR1
760 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 4); // FIR2
761 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 64); // FIR2
762 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 0); // FIR2
763 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 3); // FIR2
764 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 18); // FIR2
765 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 27); // FIR2
766 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 48); // FIR2
767 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 66); // FIR2
768 msp_writereg(av7110, MSP_WR_DEM, 0x0005, 72); // FIR2
769 msp_writereg(av7110, MSP_WR_DEM, 0x0083, 0xa000); // MODE_REG
770 msp_writereg(av7110, MSP_WR_DEM, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
771 msp_writereg(av7110, MSP_WR_DEM, 0x009b, 0x04fc); // DCO1_HI
772 msp_writereg(av7110, MSP_WR_DEM, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
773 msp_writereg(av7110, MSP_WR_DEM, 0x00ab, 0x04c6); // DCO2_HI
774 msp_writereg(av7110, MSP_WR_DEM, 0x0056, 0); // LOAD_REG 1/2
777 memcpy(standard, dvb_standard, sizeof(struct saa7146_standard) * 2);
778 /* set dd1 stream a & b */
779 saa7146_write(av7110->dev, DD1_STREAM_B, 0x00000000);
780 saa7146_write(av7110->dev, DD1_INIT, 0x03000700);
781 saa7146_write(av7110->dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
786 int av7110_init_v4l(struct av7110 *av7110)
788 struct saa7146_dev* dev = av7110->dev;
789 struct saa7146_ext_vv *vv_data;
792 /* special case DVB-C: these cards have an analog tuner
793 plus need some special handling, so we have separate
794 saa7146_ext_vv data for these... */
795 if (av7110->analog_tuner_flags)
796 vv_data = &av7110_vv_data_c;
798 vv_data = &av7110_vv_data_st;
799 ret = saa7146_vv_init(dev, vv_data);
802 ERR("cannot init capture device. skipping\n");
805 vv_data->ops.vidioc_enum_input = vidioc_enum_input;
806 vv_data->ops.vidioc_g_input = vidioc_g_input;
807 vv_data->ops.vidioc_s_input = vidioc_s_input;
808 vv_data->ops.vidioc_g_tuner = vidioc_g_tuner;
809 vv_data->ops.vidioc_s_tuner = vidioc_s_tuner;
810 vv_data->ops.vidioc_g_frequency = vidioc_g_frequency;
811 vv_data->ops.vidioc_s_frequency = vidioc_s_frequency;
812 vv_data->ops.vidioc_g_audio = vidioc_g_audio;
813 vv_data->ops.vidioc_s_audio = vidioc_s_audio;
814 vv_data->ops.vidioc_g_sliced_vbi_cap = vidioc_g_sliced_vbi_cap;
815 vv_data->ops.vidioc_g_fmt_sliced_vbi_out = vidioc_g_fmt_sliced_vbi_out;
816 vv_data->ops.vidioc_s_fmt_sliced_vbi_out = vidioc_s_fmt_sliced_vbi_out;
818 if (saa7146_register_device(&av7110->v4l_dev, dev, "av7110", VFL_TYPE_GRABBER)) {
819 ERR("cannot register capture device. skipping\n");
820 saa7146_vv_release(dev);
823 if (saa7146_register_device(&av7110->vbi_dev, dev, "av7110", VFL_TYPE_VBI))
824 ERR("cannot register vbi v4l2 device. skipping\n");
828 int av7110_exit_v4l(struct av7110 *av7110)
830 struct saa7146_dev* dev = av7110->dev;
832 saa7146_unregister_device(&av7110->v4l_dev, av7110->dev);
833 saa7146_unregister_device(&av7110->vbi_dev, av7110->dev);
835 saa7146_vv_release(dev);
842 /* FIXME: these values are experimental values that look better than the
843 values from the latest "official" driver -- at least for me... (MiHu) */
844 static struct saa7146_standard standard[] = {
846 .name = "PAL", .id = V4L2_STD_PAL_BG,
847 .v_offset = 0x15, .v_field = 288,
848 .h_offset = 0x48, .h_pixels = 708,
849 .v_max_out = 576, .h_max_out = 768,
851 .name = "NTSC", .id = V4L2_STD_NTSC,
852 .v_offset = 0x10, .v_field = 244,
853 .h_offset = 0x40, .h_pixels = 708,
854 .v_max_out = 480, .h_max_out = 640,
858 static struct saa7146_standard analog_standard[] = {
860 .name = "PAL", .id = V4L2_STD_PAL_BG,
861 .v_offset = 0x1b, .v_field = 288,
862 .h_offset = 0x08, .h_pixels = 708,
863 .v_max_out = 576, .h_max_out = 768,
865 .name = "NTSC", .id = V4L2_STD_NTSC,
866 .v_offset = 0x10, .v_field = 244,
867 .h_offset = 0x40, .h_pixels = 708,
868 .v_max_out = 480, .h_max_out = 640,
872 static struct saa7146_standard dvb_standard[] = {
874 .name = "PAL", .id = V4L2_STD_PAL_BG,
875 .v_offset = 0x14, .v_field = 288,
876 .h_offset = 0x48, .h_pixels = 708,
877 .v_max_out = 576, .h_max_out = 768,
879 .name = "NTSC", .id = V4L2_STD_NTSC,
880 .v_offset = 0x10, .v_field = 244,
881 .h_offset = 0x40, .h_pixels = 708,
882 .v_max_out = 480, .h_max_out = 640,
886 static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
888 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
890 if (std->id & V4L2_STD_PAL) {
891 av7110->vidmode = AV7110_VIDEO_MODE_PAL;
892 av7110_set_vidmode(av7110, av7110->vidmode);
894 else if (std->id & V4L2_STD_NTSC) {
895 av7110->vidmode = AV7110_VIDEO_MODE_NTSC;
896 av7110_set_vidmode(av7110, av7110->vidmode);
905 static struct saa7146_ext_vv av7110_vv_data_st = {
908 .capabilities = V4L2_CAP_SLICED_VBI_OUTPUT,
911 .stds = &standard[0],
912 .num_stds = ARRAY_SIZE(standard),
913 .std_callback = &std_callback,
915 .vbi_fops.open = av7110_vbi_reset,
916 .vbi_fops.release = av7110_vbi_reset,
917 .vbi_fops.write = av7110_vbi_write,
920 static struct saa7146_ext_vv av7110_vv_data_c = {
923 .capabilities = V4L2_CAP_TUNER | V4L2_CAP_SLICED_VBI_OUTPUT,
924 .flags = SAA7146_USE_PORT_B_FOR_VBI,
926 .stds = &standard[0],
927 .num_stds = ARRAY_SIZE(standard),
928 .std_callback = &std_callback,
930 .vbi_fops.open = av7110_vbi_reset,
931 .vbi_fops.release = av7110_vbi_reset,
932 .vbi_fops.write = av7110_vbi_write,