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.
19 * To obtain the license, point your browser to
20 * http://www.gnu.org/copyleft/gpl.html
22 * the project's page is at https://linuxtv.org
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/delay.h>
31 #include <linux/timer.h>
32 #include <linux/poll.h>
35 #include "av7110_hw.h"
36 #include "av7110_av.h"
38 int msp_writereg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16 val
)
40 u8 msg
[5] = { dev
, reg
>> 8, reg
& 0xff, val
>> 8 , val
& 0xff };
41 struct i2c_msg msgs
= { .flags
= 0, .len
= 5, .buf
= msg
};
43 switch (av7110
->adac_type
) {
44 case DVB_ADAC_MSP34x0
:
47 case DVB_ADAC_MSP34x5
:
54 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
, 1) != 1) {
55 dprintk(1, "dvb-ttpci: failed @ card %d, %u = %u\n",
56 av7110
->dvb_adapter
.num
, reg
, val
);
62 static int msp_readreg(struct av7110
*av7110
, u8 dev
, u16 reg
, u16
*val
)
64 u8 msg1
[3] = { dev
, reg
>> 8, reg
& 0xff };
66 struct i2c_msg msgs
[2] = {
67 { .flags
= 0 , .len
= 3, .buf
= msg1
},
68 { .flags
= I2C_M_RD
, .len
= 2, .buf
= msg2
}
71 switch (av7110
->adac_type
) {
72 case DVB_ADAC_MSP34x0
:
76 case DVB_ADAC_MSP34x5
:
84 if (i2c_transfer(&av7110
->i2c_adap
, &msgs
[0], 2) != 2) {
85 dprintk(1, "dvb-ttpci: failed @ card %d, %u\n",
86 av7110
->dvb_adapter
.num
, reg
);
89 *val
= (msg2
[0] << 8) | msg2
[1];
93 static struct v4l2_input inputs
[4] = {
97 .type
= V4L2_INPUT_TYPE_CAMERA
,
99 .tuner
= 0, /* ignored */
100 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
102 .capabilities
= V4L2_IN_CAP_STD
,
105 .name
= "Television",
106 .type
= V4L2_INPUT_TYPE_TUNER
,
109 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
111 .capabilities
= V4L2_IN_CAP_STD
,
115 .type
= V4L2_INPUT_TYPE_CAMERA
,
118 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
120 .capabilities
= V4L2_IN_CAP_STD
,
124 .type
= V4L2_INPUT_TYPE_CAMERA
,
127 .std
= V4L2_STD_PAL_BG
|V4L2_STD_NTSC_M
,
129 .capabilities
= V4L2_IN_CAP_STD
,
133 static int ves1820_writereg(struct saa7146_dev
*dev
, u8 addr
, u8 reg
, u8 data
)
135 struct av7110
*av7110
= dev
->ext_priv
;
136 u8 buf
[] = { 0x00, reg
, data
};
137 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= buf
, .len
= 3 };
139 dprintk(4, "dev: %p\n", dev
);
141 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
146 static int tuner_write(struct saa7146_dev
*dev
, u8 addr
, u8 data
[4])
148 struct av7110
*av7110
= dev
->ext_priv
;
149 struct i2c_msg msg
= { .addr
= addr
, .flags
= 0, .buf
= data
, .len
= 4 };
151 dprintk(4, "dev: %p\n", dev
);
153 if (1 != i2c_transfer(&av7110
->i2c_adap
, &msg
, 1))
158 static int ves1820_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
164 dprintk(4, "freq: 0x%08x\n", freq
);
166 /* magic number: 614. tuning with the frequency given by v4l2
167 is always off by 614*62.5 = 38375 kHz...*/
170 buf
[0] = (div
>> 8) & 0x7f;
174 if (freq
< (u32
) (16 * 168.25))
176 else if (freq
< (u32
) (16 * 447.25))
184 return tuner_write(dev
, 0x61, buf
);
187 static int stv0297_set_tv_freq(struct saa7146_dev
*dev
, u32 freq
)
189 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
193 div
= (freq
+ 38900000 + 31250) / 62500;
195 data
[0] = (div
>> 8) & 0x7f;
196 data
[1] = div
& 0xff;
201 else if (freq
< 137000000)
203 else if (freq
< 403000000)
205 else if (freq
< 860000000)
210 if (av7110
->fe
->ops
.i2c_gate_ctrl
)
211 av7110
->fe
->ops
.i2c_gate_ctrl(av7110
->fe
, 1);
212 return tuner_write(dev
, 0x63, data
);
217 static struct saa7146_standard analog_standard
[];
218 static struct saa7146_standard dvb_standard
[];
219 static struct saa7146_standard standard
[];
221 static const struct v4l2_audio msp3400_v4l2_audio
= {
223 .name
= "Television",
224 .capability
= V4L2_AUDCAP_STEREO
227 static int av7110_dvb_c_switch(struct saa7146_fh
*fh
)
229 struct saa7146_dev
*dev
= fh
->dev
;
230 struct saa7146_vv
*vv
= dev
->vv_data
;
231 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
233 int source
, sync
, err
;
235 dprintk(4, "%p\n", av7110
);
237 if ((vv
->video_status
& STATUS_OVERLAY
) != 0) {
238 vv
->ov_suspend
= vv
->video_fh
;
239 err
= saa7146_stop_preview(vv
->video_fh
); /* side effect: video_status is now 0, video_fh is NULL */
241 dprintk(2, "suspending video failed\n");
242 vv
->ov_suspend
= NULL
;
246 if (0 != av7110
->current_input
) {
247 dprintk(1, "switching to analog TV:\n");
249 source
= SAA7146_HPS_SOURCE_PORT_B
;
250 sync
= SAA7146_HPS_SYNC_PORT_B
;
251 memcpy(standard
, analog_standard
, sizeof(struct saa7146_standard
) * 2);
253 switch (av7110
->current_input
) {
255 dprintk(1, "switching SAA7113 to Analog Tuner Input\n");
256 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0000); // loudspeaker source
257 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0000); // headphone source
258 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0000); // SCART 1 source
259 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
260 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); // loudspeaker + headphone
261 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); // SCART 1 volume
263 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
264 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x60))
265 dprintk(1, "setting band in demodulator failed\n");
266 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
267 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTHI
); // TDA9819 pin9(STD)
268 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTHI
); // TDA9819 pin30(VIF)
270 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd0) != 1)
271 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
274 dprintk(1, "switching SAA7113 to Video AV CVBS Input\n");
275 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd2) != 1)
276 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
279 dprintk(1, "switching SAA7113 to Video AV Y/C Input\n");
280 if (i2c_writereg(av7110
, 0x48, 0x02, 0xd9) != 1)
281 dprintk(1, "saa7113 write failed @ card %d", av7110
->dvb_adapter
.num
);
284 dprintk(1, "switching SAA7113 to Input: AV7110: SAA7113: invalid input\n");
288 source
= SAA7146_HPS_SOURCE_PORT_A
;
289 sync
= SAA7146_HPS_SYNC_PORT_A
;
290 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
291 dprintk(1, "switching DVB mode\n");
292 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
293 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
294 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
295 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, 0x3000); // FM matrix, mono
296 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
297 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
299 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
300 if (ves1820_writereg(dev
, 0x09, 0x0f, 0x20))
301 dprintk(1, "setting band in demodulator failed\n");
302 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
303 saa7146_setgpio(dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
304 saa7146_setgpio(dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
308 /* hmm, this does not do anything!? */
309 if (av7110_fw_cmd(av7110
, COMTYPE_AUDIODAC
, ADSwitch
, 1, adswitch
))
310 dprintk(1, "ADSwitch error\n");
312 saa7146_set_hps_source_and_sync(dev
, source
, sync
);
314 if (vv
->ov_suspend
!= NULL
) {
315 saa7146_start_preview(vv
->ov_suspend
);
316 vv
->ov_suspend
= NULL
;
322 static int vidioc_g_tuner(struct file
*file
, void *fh
, struct v4l2_tuner
*t
)
324 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
325 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
329 dprintk(2, "VIDIOC_G_TUNER: %d\n", t
->index
);
331 if (!av7110
->analog_tuner_flags
|| t
->index
!= 0)
334 memset(t
, 0, sizeof(*t
));
335 strcpy((char *)t
->name
, "Television");
337 t
->type
= V4L2_TUNER_ANALOG_TV
;
338 t
->capability
= V4L2_TUNER_CAP_NORM
| V4L2_TUNER_CAP_STEREO
|
339 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
| V4L2_TUNER_CAP_SAP
;
340 t
->rangelow
= 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
341 t
->rangehigh
= 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
342 /* FIXME: add the real signal strength here */
346 /* FIXME: standard / stereo detection is still broken */
347 msp_readreg(av7110
, MSP_RD_DEM
, 0x007e, &stereo_det
);
348 dprintk(1, "VIDIOC_G_TUNER: msp3400 TV standard detection: 0x%04x\n", stereo_det
);
349 msp_readreg(av7110
, MSP_RD_DSP
, 0x0018, &stereo_det
);
350 dprintk(1, "VIDIOC_G_TUNER: msp3400 stereo detection: 0x%04x\n", stereo_det
);
351 stereo
= (s8
)(stereo_det
>> 8);
354 t
->rxsubchans
= V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_MONO
;
355 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
356 } else if (stereo
< -0x10) {
358 t
->rxsubchans
= V4L2_TUNER_SUB_LANG1
| V4L2_TUNER_SUB_LANG2
;
359 t
->audmode
= V4L2_TUNER_MODE_LANG1
;
361 t
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
366 static int vidioc_s_tuner(struct file
*file
, void *fh
, const struct v4l2_tuner
*t
)
368 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
369 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
371 dprintk(2, "VIDIOC_S_TUNER: %d\n", t
->index
);
373 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
376 switch (t
->audmode
) {
377 case V4L2_TUNER_MODE_STEREO
:
378 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n");
379 fm_matrix
= 0x3001; /* stereo */
382 case V4L2_TUNER_MODE_LANG1_LANG2
:
383 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n");
384 fm_matrix
= 0x3000; /* bilingual */
387 case V4L2_TUNER_MODE_LANG1
:
388 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n");
389 fm_matrix
= 0x3000; /* mono */
392 case V4L2_TUNER_MODE_LANG2
:
393 dprintk(2, "VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n");
394 fm_matrix
= 0x3000; /* mono */
397 default: /* case V4L2_TUNER_MODE_MONO: */
398 dprintk(2, "VIDIOC_S_TUNER: TDA9840_SET_MONO\n");
399 fm_matrix
= 0x3000; /* mono */
403 msp_writereg(av7110
, MSP_WR_DSP
, 0x000e, fm_matrix
);
404 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, src
);
405 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, src
);
406 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, src
);
410 static int vidioc_g_frequency(struct file
*file
, void *fh
, struct v4l2_frequency
*f
)
412 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
413 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
415 dprintk(2, "VIDIOC_G_FREQ: freq:0x%08x\n", f
->frequency
);
417 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
420 memset(f
, 0, sizeof(*f
));
421 f
->type
= V4L2_TUNER_ANALOG_TV
;
422 f
->frequency
= av7110
->current_freq
;
426 static int vidioc_s_frequency(struct file
*file
, void *fh
, const struct v4l2_frequency
*f
)
428 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
429 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
431 dprintk(2, "VIDIOC_S_FREQUENCY: freq:0x%08x\n", f
->frequency
);
433 if (!av7110
->analog_tuner_flags
|| av7110
->current_input
!= 1)
436 if (V4L2_TUNER_ANALOG_TV
!= f
->type
)
439 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0xffe0); /* fast mute */
440 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0xffe0);
442 /* tune in desired frequency */
443 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
)
444 ves1820_set_tv_freq(dev
, f
->frequency
);
445 else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
)
446 stv0297_set_tv_freq(dev
, f
->frequency
);
447 av7110
->current_freq
= f
->frequency
;
449 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x003f); /* start stereo detection */
450 msp_writereg(av7110
, MSP_WR_DSP
, 0x0015, 0x0000);
451 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x4f00); /* loudspeaker + headphone */
452 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x4f00); /* SCART 1 volume */
456 static int vidioc_enum_input(struct file
*file
, void *fh
, struct v4l2_input
*i
)
458 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
459 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
461 dprintk(2, "VIDIOC_ENUMINPUT: %d\n", i
->index
);
463 if (av7110
->analog_tuner_flags
) {
471 memcpy(i
, &inputs
[i
->index
], sizeof(struct v4l2_input
));
476 static int vidioc_g_input(struct file
*file
, void *fh
, unsigned int *input
)
478 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
479 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
481 *input
= av7110
->current_input
;
482 dprintk(2, "VIDIOC_G_INPUT: %d\n", *input
);
486 static int vidioc_s_input(struct file
*file
, void *fh
, unsigned int input
)
488 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
489 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
491 dprintk(2, "VIDIOC_S_INPUT: %d\n", input
);
493 if (!av7110
->analog_tuner_flags
)
494 return input
? -EINVAL
: 0;
499 av7110
->current_input
= input
;
500 return av7110_dvb_c_switch(fh
);
503 static int vidioc_enumaudio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
505 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
508 *a
= msp3400_v4l2_audio
;
512 static int vidioc_g_audio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
514 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
515 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
517 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
520 if (av7110
->current_input
>= 2)
522 *a
= msp3400_v4l2_audio
;
526 static int vidioc_s_audio(struct file
*file
, void *fh
, const struct v4l2_audio
*a
)
528 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
529 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
531 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a
->index
);
532 if (av7110
->current_input
>= 2)
534 return a
->index
? -EINVAL
: 0;
537 static int vidioc_g_sliced_vbi_cap(struct file
*file
, void *fh
,
538 struct v4l2_sliced_vbi_cap
*cap
)
540 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
541 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
543 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
544 if (cap
->type
!= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
)
546 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
547 cap
->service_set
= V4L2_SLICED_WSS_625
;
548 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
553 static int vidioc_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
554 struct v4l2_format
*f
)
556 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
557 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
559 dprintk(2, "VIDIOC_G_FMT:\n");
560 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
562 memset(&f
->fmt
.sliced
, 0, sizeof f
->fmt
.sliced
);
563 if (av7110
->wssMode
) {
564 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
565 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
566 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
571 static int vidioc_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
572 struct v4l2_format
*f
)
574 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
575 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
577 dprintk(2, "VIDIOC_S_FMT\n");
578 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
580 if (f
->fmt
.sliced
.service_set
!= V4L2_SLICED_WSS_625
&&
581 f
->fmt
.sliced
.service_lines
[0][23] != V4L2_SLICED_WSS_625
) {
582 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
583 /* WSS controlled by firmware */
586 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
,
589 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
590 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
591 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
592 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
593 /* WSS controlled by userspace */
600 static int av7110_vbi_reset(struct file
*file
)
602 struct saa7146_fh
*fh
= file
->private_data
;
603 struct saa7146_dev
*dev
= fh
->dev
;
604 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
606 dprintk(2, "%s\n", __func__
);
609 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
612 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 1, 0);
615 static ssize_t
av7110_vbi_write(struct file
*file
, const char __user
*data
, size_t count
, loff_t
*ppos
)
617 struct saa7146_fh
*fh
= file
->private_data
;
618 struct saa7146_dev
*dev
= fh
->dev
;
619 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
620 struct v4l2_sliced_vbi_data d
;
623 dprintk(2, "%s\n", __func__
);
624 if (FW_VERSION(av7110
->arm_app
) < 0x2623 || !av7110
->wssMode
|| count
!= sizeof d
)
626 if (copy_from_user(&d
, data
, count
))
628 if ((d
.id
!= 0 && d
.id
!= V4L2_SLICED_WSS_625
) || d
.field
!= 0 || d
.line
!= 23)
631 av7110
->wssData
= ((d
.data
[1] << 8) & 0x3f00) | d
.data
[0];
633 av7110
->wssData
= 0x8000;
634 rc
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 2, 1, av7110
->wssData
);
635 return (rc
< 0) ? rc
: count
;
638 /****************************************************************************
640 ****************************************************************************/
642 static u8 saa7113_init_regs
[] = {
701 static struct saa7146_ext_vv av7110_vv_data_st
;
702 static struct saa7146_ext_vv av7110_vv_data_c
;
704 int av7110_init_analog_module(struct av7110
*av7110
)
706 u16 version1
, version2
;
708 if (i2c_writereg(av7110
, 0x80, 0x0, 0x80) == 1 &&
709 i2c_writereg(av7110
, 0x80, 0x0, 0) == 1) {
710 pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
711 av7110
->dvb_adapter
.num
);
712 av7110
->adac_type
= DVB_ADAC_MSP34x0
;
713 } else if (i2c_writereg(av7110
, 0x84, 0x0, 0x80) == 1 &&
714 i2c_writereg(av7110
, 0x84, 0x0, 0) == 1) {
715 pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
716 av7110
->dvb_adapter
.num
);
717 av7110
->adac_type
= DVB_ADAC_MSP34x5
;
721 msleep(100); // the probing above resets the msp...
722 msp_readreg(av7110
, MSP_RD_DSP
, 0x001e, &version1
);
723 msp_readreg(av7110
, MSP_RD_DSP
, 0x001f, &version2
);
724 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
725 av7110
->dvb_adapter
.num
, version1
, version2
);
726 msp_writereg(av7110
, MSP_WR_DSP
, 0x0013, 0x0c00);
727 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
728 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
729 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
730 msp_writereg(av7110
, MSP_WR_DSP
, 0x0004, 0x7f00); // loudspeaker volume
731 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
732 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
733 msp_writereg(av7110
, MSP_WR_DSP
, 0x000d, 0x1900); // prescale SCART
735 if (i2c_writereg(av7110
, 0x48, 0x01, 0x00)!=1) {
736 pr_info("saa7113 not accessible\n");
738 u8
*i
= saa7113_init_regs
;
740 if ((av7110
->dev
->pci
->subsystem_vendor
== 0x110a) && (av7110
->dev
->pci
->subsystem_device
== 0x0000)) {
741 /* Fujitsu/Siemens DVB-Cable */
742 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
743 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x0002)) {
744 /* Hauppauge/TT DVB-C premium */
745 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
746 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x000A)) {
747 /* Hauppauge/TT DVB-C premium */
748 av7110
->analog_tuner_flags
|= ANALOG_TUNER_STV0297
;
751 /* setup for DVB by default */
752 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
753 if (ves1820_writereg(av7110
->dev
, 0x09, 0x0f, 0x20))
754 dprintk(1, "setting band in demodulator failed\n");
755 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
756 saa7146_setgpio(av7110
->dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
757 saa7146_setgpio(av7110
->dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
760 /* init the saa7113 */
762 if (i2c_writereg(av7110
, 0x48, i
[0], i
[1]) != 1) {
763 dprintk(1, "saa7113 initialization failed @ card %d", av7110
->dvb_adapter
.num
);
768 /* setup msp for analog sound: B/G Dual-FM */
769 msp_writereg(av7110
, MSP_WR_DEM
, 0x00bb, 0x02d0); // AD_CV
770 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 3); // FIR1
771 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 18); // FIR1
772 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 27); // FIR1
773 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 48); // FIR1
774 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 66); // FIR1
775 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 72); // FIR1
776 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 4); // FIR2
777 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 64); // FIR2
778 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 0); // FIR2
779 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 3); // FIR2
780 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 18); // FIR2
781 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 27); // FIR2
782 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 48); // FIR2
783 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 66); // FIR2
784 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 72); // FIR2
785 msp_writereg(av7110
, MSP_WR_DEM
, 0x0083, 0xa000); // MODE_REG
786 msp_writereg(av7110
, MSP_WR_DEM
, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
787 msp_writereg(av7110
, MSP_WR_DEM
, 0x009b, 0x04fc); // DCO1_HI
788 msp_writereg(av7110
, MSP_WR_DEM
, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
789 msp_writereg(av7110
, MSP_WR_DEM
, 0x00ab, 0x04c6); // DCO2_HI
790 msp_writereg(av7110
, MSP_WR_DEM
, 0x0056, 0); // LOAD_REG 1/2
793 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
794 /* set dd1 stream a & b */
795 saa7146_write(av7110
->dev
, DD1_STREAM_B
, 0x00000000);
796 saa7146_write(av7110
->dev
, DD1_INIT
, 0x03000700);
797 saa7146_write(av7110
->dev
, MC2
, (MASK_09
| MASK_25
| MASK_10
| MASK_26
));
802 int av7110_init_v4l(struct av7110
*av7110
)
804 struct saa7146_dev
* dev
= av7110
->dev
;
805 struct saa7146_ext_vv
*vv_data
;
808 /* special case DVB-C: these cards have an analog tuner
809 plus need some special handling, so we have separate
810 saa7146_ext_vv data for these... */
811 if (av7110
->analog_tuner_flags
)
812 vv_data
= &av7110_vv_data_c
;
814 vv_data
= &av7110_vv_data_st
;
815 ret
= saa7146_vv_init(dev
, vv_data
);
818 ERR("cannot init capture device. skipping\n");
821 vv_data
->vid_ops
.vidioc_enum_input
= vidioc_enum_input
;
822 vv_data
->vid_ops
.vidioc_g_input
= vidioc_g_input
;
823 vv_data
->vid_ops
.vidioc_s_input
= vidioc_s_input
;
824 vv_data
->vid_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
825 vv_data
->vid_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
826 vv_data
->vid_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
827 vv_data
->vid_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
828 vv_data
->vid_ops
.vidioc_enumaudio
= vidioc_enumaudio
;
829 vv_data
->vid_ops
.vidioc_g_audio
= vidioc_g_audio
;
830 vv_data
->vid_ops
.vidioc_s_audio
= vidioc_s_audio
;
831 vv_data
->vid_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
833 vv_data
->vbi_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
834 vv_data
->vbi_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
835 vv_data
->vbi_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
836 vv_data
->vbi_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
837 vv_data
->vbi_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
838 vv_data
->vbi_ops
.vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
;
839 vv_data
->vbi_ops
.vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
;
840 vv_data
->vbi_ops
.vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
;
842 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
843 vv_data
->capabilities
&= ~V4L2_CAP_SLICED_VBI_OUTPUT
;
845 if (saa7146_register_device(&av7110
->v4l_dev
, dev
, "av7110", VFL_TYPE_GRABBER
)) {
846 ERR("cannot register capture device. skipping\n");
847 saa7146_vv_release(dev
);
850 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
851 if (saa7146_register_device(&av7110
->vbi_dev
, dev
, "av7110", VFL_TYPE_VBI
))
852 ERR("cannot register vbi v4l2 device. skipping\n");
857 int av7110_exit_v4l(struct av7110
*av7110
)
859 struct saa7146_dev
* dev
= av7110
->dev
;
861 saa7146_unregister_device(&av7110
->v4l_dev
, av7110
->dev
);
862 saa7146_unregister_device(&av7110
->vbi_dev
, av7110
->dev
);
864 saa7146_vv_release(dev
);
871 /* FIXME: these values are experimental values that look better than the
872 values from the latest "official" driver -- at least for me... (MiHu) */
873 static struct saa7146_standard standard
[] = {
875 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
876 .v_offset
= 0x15, .v_field
= 288,
877 .h_offset
= 0x48, .h_pixels
= 708,
878 .v_max_out
= 576, .h_max_out
= 768,
880 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
881 .v_offset
= 0x10, .v_field
= 244,
882 .h_offset
= 0x40, .h_pixels
= 708,
883 .v_max_out
= 480, .h_max_out
= 640,
887 static struct saa7146_standard analog_standard
[] = {
889 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
890 .v_offset
= 0x1b, .v_field
= 288,
891 .h_offset
= 0x08, .h_pixels
= 708,
892 .v_max_out
= 576, .h_max_out
= 768,
894 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
895 .v_offset
= 0x10, .v_field
= 244,
896 .h_offset
= 0x40, .h_pixels
= 708,
897 .v_max_out
= 480, .h_max_out
= 640,
901 static struct saa7146_standard dvb_standard
[] = {
903 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
904 .v_offset
= 0x14, .v_field
= 288,
905 .h_offset
= 0x48, .h_pixels
= 708,
906 .v_max_out
= 576, .h_max_out
= 768,
908 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
909 .v_offset
= 0x10, .v_field
= 244,
910 .h_offset
= 0x40, .h_pixels
= 708,
911 .v_max_out
= 480, .h_max_out
= 640,
915 static int std_callback(struct saa7146_dev
* dev
, struct saa7146_standard
*std
)
917 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
919 if (std
->id
& V4L2_STD_PAL
) {
920 av7110
->vidmode
= AV7110_VIDEO_MODE_PAL
;
921 av7110_set_vidmode(av7110
, av7110
->vidmode
);
923 else if (std
->id
& V4L2_STD_NTSC
) {
924 av7110
->vidmode
= AV7110_VIDEO_MODE_NTSC
;
925 av7110_set_vidmode(av7110
, av7110
->vidmode
);
934 static struct saa7146_ext_vv av7110_vv_data_st
= {
937 .capabilities
= V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
940 .stds
= &standard
[0],
941 .num_stds
= ARRAY_SIZE(standard
),
942 .std_callback
= &std_callback
,
944 .vbi_fops
.open
= av7110_vbi_reset
,
945 .vbi_fops
.release
= av7110_vbi_reset
,
946 .vbi_fops
.write
= av7110_vbi_write
,
949 static struct saa7146_ext_vv av7110_vv_data_c
= {
952 .capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
953 .flags
= SAA7146_USE_PORT_B_FOR_VBI
,
955 .stds
= &standard
[0],
956 .num_stds
= ARRAY_SIZE(standard
),
957 .std_callback
= &std_callback
,
959 .vbi_fops
.open
= av7110_vbi_reset
,
960 .vbi_fops
.release
= av7110_vbi_reset
,
961 .vbi_fops
.write
= av7110_vbi_write
,