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/dvb/
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/delay.h>
32 #include <linux/timer.h>
33 #include <linux/poll.h>
36 #include "av7110_hw.h"
37 #include "av7110_av.h"
39 int msp_writereg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16 val
)
41 u8 msg
[5] = { dev
, reg
>> 8, reg
& 0xff, val
>> 8 , val
& 0xff };
42 struct i2c_msg msgs
= { .flags
= 0, .len
= 5, .buf
= msg
};
44 switch (av7110
->adac_type
) {
45 case DVB_ADAC_MSP34x0
:
48 case DVB_ADAC_MSP34x5
:
55 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
, 1) != 1) {
56 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
57 av7110
->dvb_adapter
.num
, reg
, val
);
63 static int msp_readreg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16
*val
)
65 u8 msg1
[3] = { dev
, reg
>> 8, reg
& 0xff };
67 struct i2c_msg msgs
[2] = {
68 { .flags
= 0 , .len
= 3, .buf
= msg1
},
69 { .flags
= I2C_M_RD
, .len
= 2, .buf
= msg2
}
72 switch (av7110
->adac_type
) {
73 case DVB_ADAC_MSP34x0
:
77 case DVB_ADAC_MSP34x5
:
85 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
[0], 2) != 2) {
86 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
87 av7110
->dvb_adapter
.num
, reg
);
90 *val
= (msg2
[0] << 8) | msg2
[1];
94 static struct v4l2_input inputs
[4] = {
98 .type
= V4L2_INPUT_TYPE_CAMERA
,
100 .tuner
= 0, /* ignored */
101 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
105 .name
= "Television",
106 .type
= V4L2_INPUT_TYPE_TUNER
,
109 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
114 .type
= V4L2_INPUT_TYPE_CAMERA
,
117 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
122 .type
= V4L2_INPUT_TYPE_CAMERA
,
125 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
130 static int ves1820_writereg(struct saa7146_dev
*dev
, u8 addr
, u8 reg
, u8 data
)
132 struct av7110
*av7110
= dev
->ext_priv
;
133 u8 buf
[] = { 0x00, reg
, data
};
134 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= buf
, .len
= 3 };
136 dprintk(4, "dev: %p\n", dev
);
138 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
143 static int tuner_write(struct saa7146_dev
*dev
, u8 addr
, u8 data
[4])
145 struct av7110
*av7110
= dev
->ext_priv
;
146 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= data
, .len
= 4 };
148 dprintk(4, "dev: %p\n", dev
);
150 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
155 static int ves1820_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
161 dprintk(4, "freq: 0x%08x\n", freq
);
163 /* magic number: 614. tuning with the frequency given by v4l2
164 is always off by 614*62.5 = 38375 kHz...*/
167 buf
[0] = (div
>> 8) & 0x7f;
171 if (freq
< (u32
) (16 * 168.25))
173 else if (freq
< (u32
) (16 * 447.25))
181 return tuner_write(dev
, 0x61, buf
);
184 static int stv0297_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
186 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
190 div
= (freq
+ 38900000 + 31250) / 62500;
192 data
[0] = (div
>> 8) & 0x7f;
193 data
[1] = div
& 0xff;
198 else if (freq
< 137000000)
200 else if (freq
< 403000000)
202 else if (freq
< 860000000)
207 if (av7110
->fe
->ops
.i2c_gate_ctrl
)
208 av7110
->fe
->ops
.i2c_gate_ctrl(av7110
->fe
, 1);
209 return tuner_write(dev
, 0x63, data
);
214 static struct saa7146_standard analog_standard
[];
215 static struct saa7146_standard dvb_standard
[];
216 static struct saa7146_standard standard
[];
218 static struct v4l2_audio msp3400_v4l2_audio
= {
220 .name
= "Television",
221 .capability
= V4L2_AUDCAP_STEREO
224 static int av7110_dvb_c_switch(struct saa7146_fh
*fh
)
226 struct saa7146_dev
*dev
= fh
->dev
;
227 struct saa7146_vv
*vv
= dev
->vv_data
;
228 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
230 int source
, sync
, err
;
232 dprintk(4, "%p\n", av7110
);
234 if ((vv
->video_status
& STATUS_OVERLAY
) != 0) {
235 vv
->ov_suspend
= vv
->video_fh
;
236 err
= saa7146_stop_preview(vv
->video_fh
); /* side effect: video_status is now 0, video_fh is NULL */
238 dprintk(2, "suspending video failed\n");
239 vv
->ov_suspend
= NULL
;
243 if (0 != av7110
->current_input
) {
244 dprintk(1, "switching to analog TV:\n");
246 source
= SAA7146_HPS_SOURCE_PORT_B
;
247 sync
= SAA7146_HPS_SYNC_PORT_B
;
248 memcpy(standard
, analog_standard
, sizeof(struct saa7146_standard
) * 2);
250 switch (av7110
->current_input
) {
252 dprintk(1, "switching SAA7113 to Analog Tuner Input.\n");
253 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0000); // loudspeaker source
254 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0000); // headphone source
255 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0000); // SCART 1 source
256 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
257 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); // loudspeaker + headphone
258 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); // SCART 1 volume
260 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
261 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x60))
262 dprintk(1, "setting band in demodulator failed.\n");
263 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
264 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTHI
); // TDA9819 pin9(STD)
265 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTHI
); // TDA9819 pin30(VIF)
267 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd0) != 1)
268 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
271 dprintk(1, "switching SAA7113 to Video AV CVBS Input.\n");
272 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd2) != 1)
273 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
276 dprintk(1, "switching SAA7113 to Video AV Y/C Input.\n");
277 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd9) != 1)
278 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
281 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input.\n");
285 source
= SAA7146_HPS_SOURCE_PORT_A
;
286 sync
= SAA7146_HPS_SYNC_PORT_A
;
287 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
288 dprintk(1, "switching DVB mode\n");
289 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
290 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
291 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
292 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
293 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
294 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
296 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
297 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x20))
298 dprintk(1, "setting band in demodulator failed.\n");
299 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
300 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
301 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
305 /* hmm, this does not do anything!? */
306 if (av7110_fw_cmd(av7110
, COMTYPE_AUDIODAC
, ADSwitch
, 1, adswitch
))
307 dprintk(1, "ADSwitch error\n");
309 saa7146_set_hps_source_and_sync(dev
, source
, sync
);
311 if (vv
->ov_suspend
!= NULL
) {
312 saa7146_start_preview(vv
->ov_suspend
);
313 vv
->ov_suspend
= NULL
;
319 static int vidioc_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*t
)
321 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
322 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
326 dprintk(2, "VIDIOC_G_TUNER: %d\n", t
->index
);
328 if (!av7110
->analog_tuner_flags
|| t
->index
!= 0)
331 memset(t
, 0, sizeof(*t
));
332 strcpy((char *)t
->name
, "Television");
334 t
->type
= V4L2_TUNER_ANALOG_TV
;
335 t
->capability
= V4L2_TUNER_CAP_NORM
| V4L2_TUNER_CAP_STEREO
|
336 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
| V4L2_TUNER_CAP_SAP
;
337 t
->rangelow
= 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
338 t
->rangehigh
= 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
342 msp_readreg(av7110
, MSP_RD_DEM
, 0x007e, &stereo_det
);
343 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det
);
344 msp_readreg(av7110
, MSP_RD_DSP
, 0x0018, &stereo_det
);
345 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det
);
346 stereo
= (s8
)(stereo_det
>> 8);
349 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_MONO
;
350 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
351 } else if (stereo
< -0x10) {
353 t
->rxsubchans
= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
354 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
356 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
361 static int vidioc_s_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*t
)
363 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
364 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
366 dprintk(2, "VIDIOC_S_TUNER: %d\n", t
->index
);
368 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
371 switch (t
->audmode
) {
372 case V4L2_TUNER_MODE_STEREO
:
373 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
374 fm_matrix
= 0x3001; /* stereo */
377 case V4L2_TUNER_MODE_LANG1_LANG2
:
378 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
379 fm_matrix
= 0x3000; /* bilingual */
382 case V4L2_TUNER_MODE_LANG1
:
383 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
384 fm_matrix
= 0x3000; /* mono */
387 case V4L2_TUNER_MODE_LANG2
:
388 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
389 fm_matrix
= 0x3000; /* mono */
392 default: /* case V4L2_TUNER_MODE_MONO: */
393 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
394 fm_matrix
= 0x3000; /* mono */
398 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, fm_matrix
);
399 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, src
);
400 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, src
);
401 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, src
);
405 static int vidioc_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*f
)
407 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
408 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
410 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x.\n", f
->frequency
);
412 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
415 memset(f
, 0, sizeof(*f
));
416 f
->type
= V4L2_TUNER_ANALOG_TV
;
417 f
->frequency
= av7110
->current_freq
;
421 static int vidioc_s_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*f
)
423 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
424 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
426 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x.\n", f
->frequency
);
428 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
431 if (V4L2_TUNER_ANALOG_TV
!= f
->type
)
434 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0xffe0); /* fast mute */
435 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0xffe0);
437 /* tune in desired frequency */
438 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
)
439 ves1820_set_tv_freq(dev
, f
->frequency
);
440 else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
)
441 stv0297_set_tv_freq(dev
, f
->frequency
);
442 av7110
->current_freq
= f
->frequency
;
444 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x003f); /* start stereo detection */
445 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x0000);
446 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); /* loudspeaker + headphone */
447 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); /* SCART 1 volume */
451 static int vidioc_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*i
)
453 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
454 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
456 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i
->index
);
458 if (av7110
->analog_tuner_flags
) {
466 memcpy(i
, &inputs
[i
->index
], sizeof(struct v4l2_input
));
471 static int vidioc_g_input(struct file
*file
, void *fh
, unsigned int *input
)
473 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
474 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
476 *input
= av7110
->current_input
;
477 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input
);
481 static int vidioc_s_input(struct file
*file
, void *fh
, unsigned int input
)
483 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
484 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
486 dprintk(2, "VIDIOC_S_INPUT: %d\n", input
);
488 if (!av7110
->analog_tuner_flags
)
494 av7110
->current_input
= input
;
495 return av7110_dvb_c_switch(fh
);
498 static int vidioc_g_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
500 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
503 memcpy(a
, &msp3400_v4l2_audio
, sizeof(struct v4l2_audio
));
507 static int vidioc_s_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
509 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a
->index
);
513 static int vidioc_g_sliced_vbi_cap(struct file
*file
, void *fh
,
514 struct v4l2_sliced_vbi_cap
*cap
)
516 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
517 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
519 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
520 if (cap
->type
!= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
)
522 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
523 cap
->service_set
= V4L2_SLICED_WSS_625
;
524 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
529 static int vidioc_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
530 struct v4l2_format
*f
)
532 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
533 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
535 dprintk(2, "VIDIOC_G_FMT:\n");
536 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
538 memset(&f
->fmt
.sliced
, 0, sizeof f
->fmt
.sliced
);
539 if (av7110
->wssMode
) {
540 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
541 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
542 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
547 static int vidioc_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
548 struct v4l2_format
*f
)
550 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
551 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
553 dprintk(2, "VIDIOC_S_FMT\n");
554 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
556 if (f
->fmt
.sliced
.service_set
!= V4L2_SLICED_WSS_625
&&
557 f
->fmt
.sliced
.service_lines
[0][23] != V4L2_SLICED_WSS_625
) {
558 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
559 /* WSS controlled by firmware */
562 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
,
565 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
566 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
567 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
568 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
569 /* WSS controlled by userspace */
576 static int av7110_vbi_reset(struct file
*file
)
578 struct saa7146_fh
*fh
= file
->private_data
;
579 struct saa7146_dev
*dev
= fh
->dev
;
580 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
582 dprintk(2, "%s\n", __func__
);
585 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
588 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 1, 0);
591 static ssize_t
av7110_vbi_write(struct file
*file
, const char __user
*data
, size_t count
, loff_t
*ppos
)
593 struct saa7146_fh
*fh
= file
->private_data
;
594 struct saa7146_dev
*dev
= fh
->dev
;
595 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
596 struct v4l2_sliced_vbi_data d
;
599 dprintk(2, "%s\n", __func__
);
600 if (FW_VERSION(av7110
->arm_app
) < 0x2623 || !av7110
->wssMode
|| count
!= sizeof d
)
602 if (copy_from_user(&d
, data
, count
))
604 if ((d
.id
!= 0 && d
.id
!= V4L2_SLICED_WSS_625
) || d
.field
!= 0 || d
.line
!= 23)
607 av7110
->wssData
= ((d
.data
[1] << 8) & 0x3f00) | d
.data
[0];
609 av7110
->wssData
= 0x8000;
610 rc
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 2, 1, av7110
->wssData
);
611 return (rc
< 0) ? rc
: count
;
614 /****************************************************************************
616 ****************************************************************************/
618 static u8 saa7113_init_regs
[] = {
677 static struct saa7146_ext_vv av7110_vv_data_st
;
678 static struct saa7146_ext_vv av7110_vv_data_c
;
680 int av7110_init_analog_module(struct av7110
*av7110
)
682 u16 version1
, version2
;
684 if (i2c_writereg(av7110
, 0x80, 0x0, 0x80) == 1 &&
685 i2c_writereg(av7110
, 0x80, 0x0, 0) == 1) {
686 printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3400\n",
687 av7110
->dvb_adapter
.num
);
688 av7110
->adac_type
= DVB_ADAC_MSP34x0
;
689 } else if (i2c_writereg(av7110
, 0x84, 0x0, 0x80) == 1 &&
690 i2c_writereg(av7110
, 0x84, 0x0, 0) == 1) {
691 printk("dvb-ttpci: DVB-C analog module @ card %d detected, initializing MSP3415\n",
692 av7110
->dvb_adapter
.num
);
693 av7110
->adac_type
= DVB_ADAC_MSP34x5
;
697 msleep(100); // the probing above resets the msp...
698 msp_readreg(av7110
, MSP_RD_DSP
, 0x001e, &version1
);
699 msp_readreg(av7110
, MSP_RD_DSP
, 0x001f, &version2
);
700 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
701 av7110
->dvb_adapter
.num
, version1
, version2
);
702 msp_writereg(av7110
, MSP_WR_DSP
, 0x0013, 0x0c00);
703 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
704 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
705 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
706 msp_writereg(av7110
, MSP_WR_DSP
, 0x0004, 0x7f00); // loudspeaker volume
707 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
708 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
709 msp_writereg(av7110
, MSP_WR_DSP
, 0x000d, 0x1900); // prescale SCART
711 if (i2c_writereg(av7110
, 0x48, 0x01, 0x00)!=1) {
712 INFO(("saa7113 not accessible.\n"));
714 u8
*i
= saa7113_init_regs
;
716 if ((av7110
->dev
->pci
->subsystem_vendor
== 0x110a) && (av7110
->dev
->pci
->subsystem_device
== 0x0000)) {
717 /* Fujitsu/Siemens DVB-Cable */
718 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
719 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x0002)) {
720 /* Hauppauge/TT DVB-C premium */
721 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
722 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x000A)) {
723 /* Hauppauge/TT DVB-C premium */
724 av7110
->analog_tuner_flags
|= ANALOG_TUNER_STV0297
;
727 /* setup for DVB by default */
728 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
729 if (ves1820_writereg(av7110
->dev
, 0x09, 0x0f, 0x20))
730 dprintk(1, "setting band in demodulator failed.\n");
731 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
732 saa7146_setgpio(av7110
->dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
733 saa7146_setgpio(av7110
->dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
736 /* init the saa7113 */
738 if (i2c_writereg(av7110
, 0x48, i
[0], i
[1]) != 1) {
739 dprintk(1, "saa7113 initialization failed @ card %d", av7110
->dvb_adapter
.num
);
744 /* setup msp for analog sound: B/G Dual-FM */
745 msp_writereg(av7110
, MSP_WR_DEM
, 0x00bb, 0x02d0); // AD_CV
746 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 3); // FIR1
747 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 18); // FIR1
748 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 27); // FIR1
749 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 48); // FIR1
750 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 66); // FIR1
751 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 72); // FIR1
752 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 4); // FIR2
753 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 64); // FIR2
754 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 0); // FIR2
755 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 3); // FIR2
756 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 18); // FIR2
757 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 27); // FIR2
758 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 48); // FIR2
759 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 66); // FIR2
760 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 72); // FIR2
761 msp_writereg(av7110
, MSP_WR_DEM
, 0x0083, 0xa000); // MODE_REG
762 msp_writereg(av7110
, MSP_WR_DEM
, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
763 msp_writereg(av7110
, MSP_WR_DEM
, 0x009b, 0x04fc); // DCO1_HI
764 msp_writereg(av7110
, MSP_WR_DEM
, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
765 msp_writereg(av7110
, MSP_WR_DEM
, 0x00ab, 0x04c6); // DCO2_HI
766 msp_writereg(av7110
, MSP_WR_DEM
, 0x0056, 0); // LOAD_REG 1/2
769 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
770 /* set dd1 stream a & b */
771 saa7146_write(av7110
->dev
, DD1_STREAM_B
, 0x00000000);
772 saa7146_write(av7110
->dev
, DD1_INIT
, 0x03000700);
773 saa7146_write(av7110
->dev
, MC2
, (MASK_09
| MASK_25
| MASK_10
| MASK_26
));
778 int av7110_init_v4l(struct av7110
*av7110
)
780 struct saa7146_dev
* dev
= av7110
->dev
;
781 struct saa7146_ext_vv
*vv_data
;
784 /* special case DVB-C: these cards have an analog tuner
785 plus need some special handling, so we have separate
786 saa7146_ext_vv data for these... */
787 if (av7110
->analog_tuner_flags
)
788 vv_data
= &av7110_vv_data_c
;
790 vv_data
= &av7110_vv_data_st
;
791 ret
= saa7146_vv_init(dev
, vv_data
);
794 ERR(("cannot init capture device. skipping.\n"));
797 vv_data
->ops
.vidioc_enum_input
= vidioc_enum_input
;
798 vv_data
->ops
.vidioc_g_input
= vidioc_g_input
;
799 vv_data
->ops
.vidioc_s_input
= vidioc_s_input
;
800 vv_data
->ops
.vidioc_g_tuner
= vidioc_g_tuner
;
801 vv_data
->ops
.vidioc_s_tuner
= vidioc_s_tuner
;
802 vv_data
->ops
.vidioc_g_frequency
= vidioc_g_frequency
;
803 vv_data
->ops
.vidioc_s_frequency
= vidioc_s_frequency
;
804 vv_data
->ops
.vidioc_g_audio
= vidioc_g_audio
;
805 vv_data
->ops
.vidioc_s_audio
= vidioc_s_audio
;
806 vv_data
->ops
.vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
;
807 vv_data
->ops
.vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
;
808 vv_data
->ops
.vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
;
810 if (saa7146_register_device(&av7110
->v4l_dev
, dev
, "av7110", VFL_TYPE_GRABBER
)) {
811 ERR(("cannot register capture device. skipping.\n"));
812 saa7146_vv_release(dev
);
815 if (saa7146_register_device(&av7110
->vbi_dev
, dev
, "av7110", VFL_TYPE_VBI
))
816 ERR(("cannot register vbi v4l2 device. skipping.\n"));
820 int av7110_exit_v4l(struct av7110
*av7110
)
822 struct saa7146_dev
* dev
= av7110
->dev
;
824 saa7146_unregister_device(&av7110
->v4l_dev
, av7110
->dev
);
825 saa7146_unregister_device(&av7110
->vbi_dev
, av7110
->dev
);
827 saa7146_vv_release(dev
);
834 static struct saa7146_standard standard
[] = {
836 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
837 .v_offset
= 0x15, .v_field
= 288,
838 .h_offset
= 0x48, .h_pixels
= 708,
839 .v_max_out
= 576, .h_max_out
= 768,
841 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
842 .v_offset
= 0x10, .v_field
= 244,
843 .h_offset
= 0x40, .h_pixels
= 708,
844 .v_max_out
= 480, .h_max_out
= 640,
848 static struct saa7146_standard analog_standard
[] = {
850 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
851 .v_offset
= 0x1b, .v_field
= 288,
852 .h_offset
= 0x08, .h_pixels
= 708,
853 .v_max_out
= 576, .h_max_out
= 768,
855 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
856 .v_offset
= 0x10, .v_field
= 244,
857 .h_offset
= 0x40, .h_pixels
= 708,
858 .v_max_out
= 480, .h_max_out
= 640,
862 static struct saa7146_standard dvb_standard
[] = {
864 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
865 .v_offset
= 0x14, .v_field
= 288,
866 .h_offset
= 0x48, .h_pixels
= 708,
867 .v_max_out
= 576, .h_max_out
= 768,
869 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
870 .v_offset
= 0x10, .v_field
= 244,
871 .h_offset
= 0x40, .h_pixels
= 708,
872 .v_max_out
= 480, .h_max_out
= 640,
876 static int std_callback(struct saa7146_dev
* dev
, struct saa7146_standard
*std
)
878 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
880 if (std
->id
& V4L2_STD_PAL
) {
881 av7110
->vidmode
= AV7110_VIDEO_MODE_PAL
;
882 av7110_set_vidmode(av7110
, av7110
->vidmode
);
884 else if (std
->id
& V4L2_STD_NTSC
) {
885 av7110
->vidmode
= AV7110_VIDEO_MODE_NTSC
;
886 av7110_set_vidmode(av7110
, av7110
->vidmode
);
895 static struct saa7146_ext_vv av7110_vv_data_st
= {
898 .capabilities
= V4L2_CAP_SLICED_VBI_OUTPUT
,
901 .stds
= &standard
[0],
902 .num_stds
= ARRAY_SIZE(standard
),
903 .std_callback
= &std_callback
,
905 .vbi_fops
.open
= av7110_vbi_reset
,
906 .vbi_fops
.release
= av7110_vbi_reset
,
907 .vbi_fops
.write
= av7110_vbi_write
,
910 static struct saa7146_ext_vv av7110_vv_data_c
= {
913 .capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_SLICED_VBI_OUTPUT
,
914 .flags
= SAA7146_USE_PORT_B_FOR_VBI
,
916 .stds
= &standard
[0],
917 .num_stds
= ARRAY_SIZE(standard
),
918 .std_callback
= &std_callback
,
920 .vbi_fops
.open
= av7110_vbi_reset
,
921 .vbi_fops
.release
= av7110_vbi_reset
,
922 .vbi_fops
.write
= av7110_vbi_write
,