1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * av7110_v4l.c: av7110 video4linux interface for DVB and Siemens DVB-C analog module
5 * Copyright (C) 1999-2002 Ralph Metzler
6 * & Marcus Metzler for convergence integrated media GmbH
8 * originally based on code by:
9 * Copyright (C) 1998,1999 Christian Theiss <mistert@rz.fh-augsburg.de>
11 * the project's page is at https://linuxtv.org
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/kernel.h>
17 #include <linux/types.h>
18 #include <linux/delay.h>
20 #include <linux/timer.h>
21 #include <linux/poll.h>
24 #include "av7110_hw.h"
25 #include "av7110_av.h"
27 int msp_writereg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16 val
)
29 u8 msg
[5] = { dev
, reg
>> 8, reg
& 0xff, val
>> 8 , val
& 0xff };
30 struct i2c_msg msgs
= { .flags
= 0, .len
= 5, .buf
= msg
};
32 switch (av7110
->adac_type
) {
33 case DVB_ADAC_MSP34x0
:
36 case DVB_ADAC_MSP34x5
:
43 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
, 1) != 1) {
44 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
45 av7110
->dvb_adapter
.num
, reg
, val
);
51 static int msp_readreg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16
*val
)
53 u8 msg1
[3] = { dev
, reg
>> 8, reg
& 0xff };
55 struct i2c_msg msgs
[2] = {
56 { .flags
= 0 , .len
= 3, .buf
= msg1
},
57 { .flags
= I2C_M_RD
, .len
= 2, .buf
= msg2
}
60 switch (av7110
->adac_type
) {
61 case DVB_ADAC_MSP34x0
:
65 case DVB_ADAC_MSP34x5
:
73 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
[0], 2) != 2) {
74 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
75 av7110
->dvb_adapter
.num
, reg
);
78 *val
= (msg2
[0] << 8) | msg2
[1];
82 static struct v4l2_input inputs
[4] = {
86 .type
= V4L2_INPUT_TYPE_CAMERA
,
88 .tuner
= 0, /* ignored */
89 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
91 .capabilities
= V4L2_IN_CAP_STD
,
95 .type
= V4L2_INPUT_TYPE_TUNER
,
98 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
100 .capabilities
= V4L2_IN_CAP_STD
,
104 .type
= V4L2_INPUT_TYPE_CAMERA
,
107 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
109 .capabilities
= V4L2_IN_CAP_STD
,
113 .type
= V4L2_INPUT_TYPE_CAMERA
,
116 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
118 .capabilities
= V4L2_IN_CAP_STD
,
122 static int ves1820_writereg(struct saa7146_dev
*dev
, u8 addr
, u8 reg
, u8 data
)
124 struct av7110
*av7110
= dev
->ext_priv
;
125 u8 buf
[] = { 0x00, reg
, data
};
126 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= buf
, .len
= 3 };
128 dprintk(4, "dev: %p\n", dev
);
130 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
135 static int tuner_write(struct saa7146_dev
*dev
, u8 addr
, u8 data
[4])
137 struct av7110
*av7110
= dev
->ext_priv
;
138 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= data
, .len
= 4 };
140 dprintk(4, "dev: %p\n", dev
);
142 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
147 static int ves1820_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
153 dprintk(4, "freq: 0x%08x\n", freq
);
155 /* magic number: 614. tuning with the frequency given by v4l2
156 is always off by 614*62.5 = 38375 kHz...*/
159 buf
[0] = (div
>> 8) & 0x7f;
163 if (freq
< 16U * 16825 / 100)
165 else if (freq
< 16U * 44725 / 100)
173 return tuner_write(dev
, 0x61, buf
);
176 static int stv0297_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
178 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
182 div
= (freq
+ 38900000 + 31250) / 62500;
184 data
[0] = (div
>> 8) & 0x7f;
185 data
[1] = div
& 0xff;
190 else if (freq
< 137000000)
192 else if (freq
< 403000000)
194 else if (freq
< 860000000)
199 if (av7110
->fe
->ops
.i2c_gate_ctrl
)
200 av7110
->fe
->ops
.i2c_gate_ctrl(av7110
->fe
, 1);
201 return tuner_write(dev
, 0x63, data
);
206 static struct saa7146_standard analog_standard
[];
207 static struct saa7146_standard dvb_standard
[];
208 static struct saa7146_standard standard
[];
210 static const struct v4l2_audio msp3400_v4l2_audio
= {
212 .name
= "Television",
213 .capability
= V4L2_AUDCAP_STEREO
216 static int av7110_dvb_c_switch(struct saa7146_fh
*fh
)
218 struct saa7146_dev
*dev
= fh
->dev
;
219 struct saa7146_vv
*vv
= dev
->vv_data
;
220 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
222 int source
, sync
, err
;
224 dprintk(4, "%p\n", av7110
);
226 if ((vv
->video_status
& STATUS_OVERLAY
) != 0) {
227 vv
->ov_suspend
= vv
->video_fh
;
228 err
= saa7146_stop_preview(vv
->video_fh
); /* side effect: video_status is now 0, video_fh is NULL */
230 dprintk(2, "suspending video failed\n");
231 vv
->ov_suspend
= NULL
;
235 if (0 != av7110
->current_input
) {
236 dprintk(1, "switching to analog TV:\n");
238 source
= SAA7146_HPS_SOURCE_PORT_B
;
239 sync
= SAA7146_HPS_SYNC_PORT_B
;
240 memcpy(standard
, analog_standard
, sizeof(struct saa7146_standard
) * 2);
242 switch (av7110
->current_input
) {
244 dprintk(1, "switching SAA7113 to Analog Tuner Input\n");
245 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0000); // loudspeaker source
246 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0000); // headphone source
247 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0000); // SCART 1 source
248 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
249 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); // loudspeaker + headphone
250 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); // SCART 1 volume
252 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
253 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x60))
254 dprintk(1, "setting band in demodulator failed\n");
255 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
256 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTHI
); // TDA9819 pin9(STD)
257 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTHI
); // TDA9819 pin30(VIF)
259 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd0) != 1)
260 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
263 dprintk(1, "switching SAA7113 to Video AV CVBS Input\n");
264 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd2) != 1)
265 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
268 dprintk(1, "switching SAA7113 to Video AV Y/C Input\n");
269 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd9) != 1)
270 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
273 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input\n");
277 source
= SAA7146_HPS_SOURCE_PORT_A
;
278 sync
= SAA7146_HPS_SYNC_PORT_A
;
279 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
280 dprintk(1, "switching DVB mode\n");
281 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
282 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
283 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
284 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
285 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
286 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
288 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
289 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x20))
290 dprintk(1, "setting band in demodulator failed\n");
291 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
292 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
293 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
297 /* hmm, this does not do anything!? */
298 if (av7110_fw_cmd(av7110
, COMTYPE_AUDIODAC
, ADSwitch
, 1, adswitch
))
299 dprintk(1, "ADSwitch error\n");
301 saa7146_set_hps_source_and_sync(dev
, source
, sync
);
303 if (vv
->ov_suspend
!= NULL
) {
304 saa7146_start_preview(vv
->ov_suspend
);
305 vv
->ov_suspend
= NULL
;
311 static int vidioc_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*t
)
313 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
314 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
318 dprintk(2, "VIDIOC_G_TUNER: %d\n", t
->index
);
320 if (!av7110
->analog_tuner_flags
|| t
->index
!= 0)
323 memset(t
, 0, sizeof(*t
));
324 strscpy((char *)t
->name
, "Television", sizeof(t
->name
));
326 t
->type
= V4L2_TUNER_ANALOG_TV
;
327 t
->capability
= V4L2_TUNER_CAP_NORM
| V4L2_TUNER_CAP_STEREO
|
328 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
| V4L2_TUNER_CAP_SAP
;
329 t
->rangelow
= 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
330 t
->rangehigh
= 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
331 /* FIXME: add the real signal strength here */
335 /* FIXME: standard / stereo detection is still broken */
336 msp_readreg(av7110
, MSP_RD_DEM
, 0x007e, &stereo_det
);
337 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det
);
338 msp_readreg(av7110
, MSP_RD_DSP
, 0x0018, &stereo_det
);
339 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det
);
340 stereo
= (s8
)(stereo_det
>> 8);
343 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_MONO
;
344 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
345 } else if (stereo
< -0x10) {
347 t
->rxsubchans
= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
348 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
350 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
355 static int vidioc_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*t
)
357 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
358 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
360 dprintk(2, "VIDIOC_S_TUNER: %d\n", t
->index
);
362 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
365 switch (t
->audmode
) {
366 case V4L2_TUNER_MODE_STEREO
:
367 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
368 fm_matrix
= 0x3001; /* stereo */
371 case V4L2_TUNER_MODE_LANG1_LANG2
:
372 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
373 fm_matrix
= 0x3000; /* bilingual */
376 case V4L2_TUNER_MODE_LANG1
:
377 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
378 fm_matrix
= 0x3000; /* mono */
381 case V4L2_TUNER_MODE_LANG2
:
382 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
383 fm_matrix
= 0x3000; /* mono */
386 default: /* case V4L2_TUNER_MODE_MONO: */
387 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
388 fm_matrix
= 0x3000; /* mono */
392 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, fm_matrix
);
393 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, src
);
394 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, src
);
395 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, src
);
399 static int vidioc_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*f
)
401 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
402 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
404 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x\n", f
->frequency
);
406 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
409 memset(f
, 0, sizeof(*f
));
410 f
->type
= V4L2_TUNER_ANALOG_TV
;
411 f
->frequency
= av7110
->current_freq
;
415 static int vidioc_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*f
)
417 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
418 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
420 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x\n", f
->frequency
);
422 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
425 if (V4L2_TUNER_ANALOG_TV
!= f
->type
)
428 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0xffe0); /* fast mute */
429 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0xffe0);
431 /* tune in desired frequency */
432 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
)
433 ves1820_set_tv_freq(dev
, f
->frequency
);
434 else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
)
435 stv0297_set_tv_freq(dev
, f
->frequency
);
436 av7110
->current_freq
= f
->frequency
;
438 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x003f); /* start stereo detection */
439 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x0000);
440 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); /* loudspeaker + headphone */
441 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); /* SCART 1 volume */
445 static int vidioc_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*i
)
447 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
448 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
450 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i
->index
);
452 if (av7110
->analog_tuner_flags
) {
460 memcpy(i
, &inputs
[i
->index
], sizeof(struct v4l2_input
));
465 static int vidioc_g_input(struct file
*file
, void *fh
, unsigned int *input
)
467 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
468 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
470 *input
= av7110
->current_input
;
471 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input
);
475 static int vidioc_s_input(struct file
*file
, void *fh
, unsigned int input
)
477 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
478 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
480 dprintk(2, "VIDIOC_S_INPUT: %d\n", input
);
482 if (!av7110
->analog_tuner_flags
)
483 return input
? -EINVAL
: 0;
488 av7110
->current_input
= input
;
489 return av7110_dvb_c_switch(fh
);
492 static int vidioc_enumaudio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
494 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
497 *a
= msp3400_v4l2_audio
;
501 static int vidioc_g_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
503 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
504 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
506 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
509 if (av7110
->current_input
>= 2)
511 *a
= msp3400_v4l2_audio
;
515 static int vidioc_s_audio(struct file
*file
, void *fh
, const struct v4l2_audio
*a
)
517 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
518 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
520 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a
->index
);
521 if (av7110
->current_input
>= 2)
523 return a
->index
? -EINVAL
: 0;
526 static int vidioc_g_sliced_vbi_cap(struct file
*file
, void *fh
,
527 struct v4l2_sliced_vbi_cap
*cap
)
529 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
530 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
532 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
533 if (cap
->type
!= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
)
535 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
536 cap
->service_set
= V4L2_SLICED_WSS_625
;
537 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
542 static int vidioc_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
543 struct v4l2_format
*f
)
545 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
546 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
548 dprintk(2, "VIDIOC_G_FMT:\n");
549 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
551 memset(&f
->fmt
.sliced
, 0, sizeof f
->fmt
.sliced
);
552 if (av7110
->wssMode
) {
553 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
554 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
555 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
560 static int vidioc_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
561 struct v4l2_format
*f
)
563 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
564 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
566 dprintk(2, "VIDIOC_S_FMT\n");
567 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
569 if (f
->fmt
.sliced
.service_set
!= V4L2_SLICED_WSS_625
&&
570 f
->fmt
.sliced
.service_lines
[0][23] != V4L2_SLICED_WSS_625
) {
571 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
572 /* WSS controlled by firmware */
575 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
,
578 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
579 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
580 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
581 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
582 /* WSS controlled by userspace */
589 static int av7110_vbi_reset(struct file
*file
)
591 struct saa7146_fh
*fh
= file
->private_data
;
592 struct saa7146_dev
*dev
= fh
->dev
;
593 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
595 dprintk(2, "%s\n", __func__
);
598 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
601 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 1, 0);
604 static ssize_t
av7110_vbi_write(struct file
*file
, const char __user
*data
, size_t count
, loff_t
*ppos
)
606 struct saa7146_fh
*fh
= file
->private_data
;
607 struct saa7146_dev
*dev
= fh
->dev
;
608 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
609 struct v4l2_sliced_vbi_data d
;
612 dprintk(2, "%s\n", __func__
);
613 if (FW_VERSION(av7110
->arm_app
) < 0x2623 || !av7110
->wssMode
|| count
!= sizeof d
)
615 if (copy_from_user(&d
, data
, count
))
617 if ((d
.id
!= 0 && d
.id
!= V4L2_SLICED_WSS_625
) || d
.field
!= 0 || d
.line
!= 23)
620 av7110
->wssData
= ((d
.data
[1] << 8) & 0x3f00) | d
.data
[0];
622 av7110
->wssData
= 0x8000;
623 rc
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 2, 1, av7110
->wssData
);
624 return (rc
< 0) ? rc
: count
;
627 /****************************************************************************
629 ****************************************************************************/
631 static u8 saa7113_init_regs
[] = {
690 static struct saa7146_ext_vv av7110_vv_data_st
;
691 static struct saa7146_ext_vv av7110_vv_data_c
;
693 int av7110_init_analog_module(struct av7110
*av7110
)
695 u16 version1
, version2
;
697 if (i2c_writereg(av7110
, 0x80, 0x0, 0x80) == 1 &&
698 i2c_writereg(av7110
, 0x80, 0x0, 0) == 1) {
699 pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
700 av7110
->dvb_adapter
.num
);
701 av7110
->adac_type
= DVB_ADAC_MSP34x0
;
702 } else if (i2c_writereg(av7110
, 0x84, 0x0, 0x80) == 1 &&
703 i2c_writereg(av7110
, 0x84, 0x0, 0) == 1) {
704 pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
705 av7110
->dvb_adapter
.num
);
706 av7110
->adac_type
= DVB_ADAC_MSP34x5
;
710 msleep(100); // the probing above resets the msp...
711 msp_readreg(av7110
, MSP_RD_DSP
, 0x001e, &version1
);
712 msp_readreg(av7110
, MSP_RD_DSP
, 0x001f, &version2
);
713 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
714 av7110
->dvb_adapter
.num
, version1
, version2
);
715 msp_writereg(av7110
, MSP_WR_DSP
, 0x0013, 0x0c00);
716 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
717 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
718 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
719 msp_writereg(av7110
, MSP_WR_DSP
, 0x0004, 0x7f00); // loudspeaker volume
720 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
721 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
722 msp_writereg(av7110
, MSP_WR_DSP
, 0x000d, 0x1900); // prescale SCART
724 if (i2c_writereg(av7110
, 0x48, 0x01, 0x00)!=1) {
725 pr_info("saa7113 not accessible\n");
727 u8
*i
= saa7113_init_regs
;
729 if ((av7110
->dev
->pci
->subsystem_vendor
== 0x110a) && (av7110
->dev
->pci
->subsystem_device
== 0x0000)) {
730 /* Fujitsu/Siemens DVB-Cable */
731 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
732 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x0002)) {
733 /* Hauppauge/TT DVB-C premium */
734 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
735 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x000A)) {
736 /* Hauppauge/TT DVB-C premium */
737 av7110
->analog_tuner_flags
|= ANALOG_TUNER_STV0297
;
740 /* setup for DVB by default */
741 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
742 if (ves1820_writereg(av7110
->dev
, 0x09, 0x0f, 0x20))
743 dprintk(1, "setting band in demodulator failed\n");
744 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
745 saa7146_setgpio(av7110
->dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
746 saa7146_setgpio(av7110
->dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
749 /* init the saa7113 */
751 if (i2c_writereg(av7110
, 0x48, i
[0], i
[1]) != 1) {
752 dprintk(1, "saa7113 initialization failed @ card %d", av7110
->dvb_adapter
.num
);
757 /* setup msp for analog sound: B/G Dual-FM */
758 msp_writereg(av7110
, MSP_WR_DEM
, 0x00bb, 0x02d0); // AD_CV
759 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 3); // FIR1
760 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 18); // FIR1
761 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 27); // FIR1
762 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 48); // FIR1
763 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 66); // FIR1
764 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 72); // FIR1
765 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 4); // FIR2
766 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 64); // FIR2
767 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 0); // FIR2
768 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 3); // FIR2
769 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 18); // FIR2
770 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 27); // FIR2
771 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 48); // FIR2
772 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 66); // FIR2
773 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 72); // FIR2
774 msp_writereg(av7110
, MSP_WR_DEM
, 0x0083, 0xa000); // MODE_REG
775 msp_writereg(av7110
, MSP_WR_DEM
, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
776 msp_writereg(av7110
, MSP_WR_DEM
, 0x009b, 0x04fc); // DCO1_HI
777 msp_writereg(av7110
, MSP_WR_DEM
, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
778 msp_writereg(av7110
, MSP_WR_DEM
, 0x00ab, 0x04c6); // DCO2_HI
779 msp_writereg(av7110
, MSP_WR_DEM
, 0x0056, 0); // LOAD_REG 1/2
782 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
783 /* set dd1 stream a & b */
784 saa7146_write(av7110
->dev
, DD1_STREAM_B
, 0x00000000);
785 saa7146_write(av7110
->dev
, DD1_INIT
, 0x03000700);
786 saa7146_write(av7110
->dev
, MC2
, (MASK_09
| MASK_25
| MASK_10
| MASK_26
));
791 int av7110_init_v4l(struct av7110
*av7110
)
793 struct saa7146_dev
* dev
= av7110
->dev
;
794 struct saa7146_ext_vv
*vv_data
;
797 /* special case DVB-C: these cards have an analog tuner
798 plus need some special handling, so we have separate
799 saa7146_ext_vv data for these... */
800 if (av7110
->analog_tuner_flags
)
801 vv_data
= &av7110_vv_data_c
;
803 vv_data
= &av7110_vv_data_st
;
804 ret
= saa7146_vv_init(dev
, vv_data
);
807 ERR("cannot init capture device. skipping\n");
810 vv_data
->vid_ops
.vidioc_enum_input
= vidioc_enum_input
;
811 vv_data
->vid_ops
.vidioc_g_input
= vidioc_g_input
;
812 vv_data
->vid_ops
.vidioc_s_input
= vidioc_s_input
;
813 vv_data
->vid_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
814 vv_data
->vid_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
815 vv_data
->vid_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
816 vv_data
->vid_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
817 vv_data
->vid_ops
.vidioc_enumaudio
= vidioc_enumaudio
;
818 vv_data
->vid_ops
.vidioc_g_audio
= vidioc_g_audio
;
819 vv_data
->vid_ops
.vidioc_s_audio
= vidioc_s_audio
;
820 vv_data
->vid_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
822 vv_data
->vbi_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
823 vv_data
->vbi_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
824 vv_data
->vbi_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
825 vv_data
->vbi_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
826 vv_data
->vbi_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
827 vv_data
->vbi_ops
.vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
;
828 vv_data
->vbi_ops
.vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
;
829 vv_data
->vbi_ops
.vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
;
831 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
832 vv_data
->capabilities
&= ~V4L2_CAP_SLICED_VBI_OUTPUT
;
834 if (saa7146_register_device(&av7110
->v4l_dev
, dev
, "av7110", VFL_TYPE_VIDEO
)) {
835 ERR("cannot register capture device. skipping\n");
836 saa7146_vv_release(dev
);
839 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
840 if (saa7146_register_device(&av7110
->vbi_dev
, dev
, "av7110", VFL_TYPE_VBI
))
841 ERR("cannot register vbi v4l2 device. skipping\n");
846 int av7110_exit_v4l(struct av7110
*av7110
)
848 struct saa7146_dev
* dev
= av7110
->dev
;
850 saa7146_unregister_device(&av7110
->v4l_dev
, av7110
->dev
);
851 saa7146_unregister_device(&av7110
->vbi_dev
, av7110
->dev
);
853 saa7146_vv_release(dev
);
860 /* FIXME: these values are experimental values that look better than the
861 values from the latest "official" driver -- at least for me... (MiHu) */
862 static struct saa7146_standard standard
[] = {
864 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
865 .v_offset
= 0x15, .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 struct saa7146_standard analog_standard
[] = {
878 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
879 .v_offset
= 0x1b, .v_field
= 288,
880 .h_offset
= 0x08, .h_pixels
= 708,
881 .v_max_out
= 576, .h_max_out
= 768,
883 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
884 .v_offset
= 0x10, .v_field
= 244,
885 .h_offset
= 0x40, .h_pixels
= 708,
886 .v_max_out
= 480, .h_max_out
= 640,
890 static struct saa7146_standard dvb_standard
[] = {
892 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
893 .v_offset
= 0x14, .v_field
= 288,
894 .h_offset
= 0x48, .h_pixels
= 708,
895 .v_max_out
= 576, .h_max_out
= 768,
897 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
898 .v_offset
= 0x10, .v_field
= 244,
899 .h_offset
= 0x40, .h_pixels
= 708,
900 .v_max_out
= 480, .h_max_out
= 640,
904 static int std_callback(struct saa7146_dev
* dev
, struct saa7146_standard
*std
)
906 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
908 if (std
->id
& V4L2_STD_PAL
) {
909 av7110
->vidmode
= AV7110_VIDEO_MODE_PAL
;
910 av7110_set_vidmode(av7110
, av7110
->vidmode
);
912 else if (std
->id
& V4L2_STD_NTSC
) {
913 av7110
->vidmode
= AV7110_VIDEO_MODE_NTSC
;
914 av7110_set_vidmode(av7110
, av7110
->vidmode
);
923 static struct saa7146_ext_vv av7110_vv_data_st
= {
926 .capabilities
= V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
929 .stds
= &standard
[0],
930 .num_stds
= ARRAY_SIZE(standard
),
931 .std_callback
= &std_callback
,
933 .vbi_fops
.open
= av7110_vbi_reset
,
934 .vbi_fops
.release
= av7110_vbi_reset
,
935 .vbi_fops
.write
= av7110_vbi_write
,
938 static struct saa7146_ext_vv av7110_vv_data_c
= {
941 .capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
942 .flags
= SAA7146_USE_PORT_B_FOR_VBI
,
944 .stds
= &standard
[0],
945 .num_stds
= ARRAY_SIZE(standard
),
946 .std_callback
= &std_callback
,
948 .vbi_fops
.open
= av7110_vbi_reset
,
949 .vbi_fops
.release
= av7110_vbi_reset
,
950 .vbi_fops
.write
= av7110_vbi_write
,