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
, const 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
, const 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
)
497 return input
? -EINVAL
: 0;
502 av7110
->current_input
= input
;
503 return av7110_dvb_c_switch(fh
);
506 static int vidioc_enumaudio(struct file
*file
, void *fh
, struct v4l2_audio
*a
)
508 dprintk(2, "VIDIOC_G_AUDIO: %d\n", a
->index
);
511 *a
= msp3400_v4l2_audio
;
515 static int vidioc_g_audio(struct file
*file
, void *fh
, 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_G_AUDIO: %d\n", a
->index
);
523 if (av7110
->current_input
>= 2)
525 *a
= msp3400_v4l2_audio
;
529 static int vidioc_s_audio(struct file
*file
, void *fh
, const struct v4l2_audio
*a
)
531 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
532 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
534 dprintk(2, "VIDIOC_S_AUDIO: %d\n", a
->index
);
535 if (av7110
->current_input
>= 2)
537 return a
->index
? -EINVAL
: 0;
540 static int vidioc_g_sliced_vbi_cap(struct file
*file
, void *fh
,
541 struct v4l2_sliced_vbi_cap
*cap
)
543 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
544 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
546 dprintk(2, "VIDIOC_G_SLICED_VBI_CAP\n");
547 if (cap
->type
!= V4L2_BUF_TYPE_SLICED_VBI_OUTPUT
)
549 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
550 cap
->service_set
= V4L2_SLICED_WSS_625
;
551 cap
->service_lines
[0][23] = V4L2_SLICED_WSS_625
;
556 static int vidioc_g_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
557 struct v4l2_format
*f
)
559 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
560 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
562 dprintk(2, "VIDIOC_G_FMT:\n");
563 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
565 memset(&f
->fmt
.sliced
, 0, sizeof f
->fmt
.sliced
);
566 if (av7110
->wssMode
) {
567 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
568 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
569 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
574 static int vidioc_s_fmt_sliced_vbi_out(struct file
*file
, void *fh
,
575 struct v4l2_format
*f
)
577 struct saa7146_dev
*dev
= ((struct saa7146_fh
*)fh
)->dev
;
578 struct av7110
*av7110
= (struct av7110
*)dev
->ext_priv
;
580 dprintk(2, "VIDIOC_S_FMT\n");
581 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
583 if (f
->fmt
.sliced
.service_set
!= V4L2_SLICED_WSS_625
&&
584 f
->fmt
.sliced
.service_lines
[0][23] != V4L2_SLICED_WSS_625
) {
585 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
586 /* WSS controlled by firmware */
589 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
,
592 memset(&f
->fmt
.sliced
, 0, sizeof(f
->fmt
.sliced
));
593 f
->fmt
.sliced
.service_set
= V4L2_SLICED_WSS_625
;
594 f
->fmt
.sliced
.service_lines
[0][23] = V4L2_SLICED_WSS_625
;
595 f
->fmt
.sliced
.io_size
= sizeof(struct v4l2_sliced_vbi_data
);
596 /* WSS controlled by userspace */
603 static int av7110_vbi_reset(struct file
*file
)
605 struct saa7146_fh
*fh
= file
->private_data
;
606 struct saa7146_dev
*dev
= fh
->dev
;
607 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
609 dprintk(2, "%s\n", __func__
);
612 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
615 return av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 1, 0);
618 static ssize_t
av7110_vbi_write(struct file
*file
, const char __user
*data
, size_t count
, loff_t
*ppos
)
620 struct saa7146_fh
*fh
= file
->private_data
;
621 struct saa7146_dev
*dev
= fh
->dev
;
622 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
623 struct v4l2_sliced_vbi_data d
;
626 dprintk(2, "%s\n", __func__
);
627 if (FW_VERSION(av7110
->arm_app
) < 0x2623 || !av7110
->wssMode
|| count
!= sizeof d
)
629 if (copy_from_user(&d
, data
, count
))
631 if ((d
.id
!= 0 && d
.id
!= V4L2_SLICED_WSS_625
) || d
.field
!= 0 || d
.line
!= 23)
634 av7110
->wssData
= ((d
.data
[1] << 8) & 0x3f00) | d
.data
[0];
636 av7110
->wssData
= 0x8000;
637 rc
= av7110_fw_cmd(av7110
, COMTYPE_ENCODER
, SetWSSConfig
, 2, 1, av7110
->wssData
);
638 return (rc
< 0) ? rc
: count
;
641 /****************************************************************************
643 ****************************************************************************/
645 static u8 saa7113_init_regs
[] = {
704 static struct saa7146_ext_vv av7110_vv_data_st
;
705 static struct saa7146_ext_vv av7110_vv_data_c
;
707 int av7110_init_analog_module(struct av7110
*av7110
)
709 u16 version1
, version2
;
711 if (i2c_writereg(av7110
, 0x80, 0x0, 0x80) == 1 &&
712 i2c_writereg(av7110
, 0x80, 0x0, 0) == 1) {
713 pr_info("DVB-C analog module @ card %d detected, initializing MSP3400\n",
714 av7110
->dvb_adapter
.num
);
715 av7110
->adac_type
= DVB_ADAC_MSP34x0
;
716 } else if (i2c_writereg(av7110
, 0x84, 0x0, 0x80) == 1 &&
717 i2c_writereg(av7110
, 0x84, 0x0, 0) == 1) {
718 pr_info("DVB-C analog module @ card %d detected, initializing MSP3415\n",
719 av7110
->dvb_adapter
.num
);
720 av7110
->adac_type
= DVB_ADAC_MSP34x5
;
724 msleep(100); // the probing above resets the msp...
725 msp_readreg(av7110
, MSP_RD_DSP
, 0x001e, &version1
);
726 msp_readreg(av7110
, MSP_RD_DSP
, 0x001f, &version2
);
727 dprintk(1, "dvb-ttpci: @ card %d MSP34xx version 0x%04x 0x%04x\n",
728 av7110
->dvb_adapter
.num
, version1
, version2
);
729 msp_writereg(av7110
, MSP_WR_DSP
, 0x0013, 0x0c00);
730 msp_writereg(av7110
, MSP_WR_DSP
, 0x0000, 0x7f00); // loudspeaker + headphone
731 msp_writereg(av7110
, MSP_WR_DSP
, 0x0008, 0x0220); // loudspeaker source
732 msp_writereg(av7110
, MSP_WR_DSP
, 0x0009, 0x0220); // headphone source
733 msp_writereg(av7110
, MSP_WR_DSP
, 0x0004, 0x7f00); // loudspeaker volume
734 msp_writereg(av7110
, MSP_WR_DSP
, 0x000a, 0x0220); // SCART 1 source
735 msp_writereg(av7110
, MSP_WR_DSP
, 0x0007, 0x7f00); // SCART 1 volume
736 msp_writereg(av7110
, MSP_WR_DSP
, 0x000d, 0x1900); // prescale SCART
738 if (i2c_writereg(av7110
, 0x48, 0x01, 0x00)!=1) {
739 pr_info("saa7113 not accessible\n");
741 u8
*i
= saa7113_init_regs
;
743 if ((av7110
->dev
->pci
->subsystem_vendor
== 0x110a) && (av7110
->dev
->pci
->subsystem_device
== 0x0000)) {
744 /* Fujitsu/Siemens DVB-Cable */
745 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
746 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x0002)) {
747 /* Hauppauge/TT DVB-C premium */
748 av7110
->analog_tuner_flags
|= ANALOG_TUNER_VES1820
;
749 } else if ((av7110
->dev
->pci
->subsystem_vendor
== 0x13c2) && (av7110
->dev
->pci
->subsystem_device
== 0x000A)) {
750 /* Hauppauge/TT DVB-C premium */
751 av7110
->analog_tuner_flags
|= ANALOG_TUNER_STV0297
;
754 /* setup for DVB by default */
755 if (av7110
->analog_tuner_flags
& ANALOG_TUNER_VES1820
) {
756 if (ves1820_writereg(av7110
->dev
, 0x09, 0x0f, 0x20))
757 dprintk(1, "setting band in demodulator failed\n");
758 } else if (av7110
->analog_tuner_flags
& ANALOG_TUNER_STV0297
) {
759 saa7146_setgpio(av7110
->dev
, 1, SAA7146_GPIO_OUTLO
); // TDA9819 pin9(STD)
760 saa7146_setgpio(av7110
->dev
, 3, SAA7146_GPIO_OUTLO
); // TDA9819 pin30(VIF)
763 /* init the saa7113 */
765 if (i2c_writereg(av7110
, 0x48, i
[0], i
[1]) != 1) {
766 dprintk(1, "saa7113 initialization failed @ card %d", av7110
->dvb_adapter
.num
);
771 /* setup msp for analog sound: B/G Dual-FM */
772 msp_writereg(av7110
, MSP_WR_DEM
, 0x00bb, 0x02d0); // AD_CV
773 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 3); // FIR1
774 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 18); // FIR1
775 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 27); // FIR1
776 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 48); // FIR1
777 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 66); // FIR1
778 msp_writereg(av7110
, MSP_WR_DEM
, 0x0001, 72); // FIR1
779 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 4); // FIR2
780 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 64); // FIR2
781 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 0); // FIR2
782 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 3); // FIR2
783 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 18); // FIR2
784 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 27); // FIR2
785 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 48); // FIR2
786 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 66); // FIR2
787 msp_writereg(av7110
, MSP_WR_DEM
, 0x0005, 72); // FIR2
788 msp_writereg(av7110
, MSP_WR_DEM
, 0x0083, 0xa000); // MODE_REG
789 msp_writereg(av7110
, MSP_WR_DEM
, 0x0093, 0x00aa); // DCO1_LO 5.74MHz
790 msp_writereg(av7110
, MSP_WR_DEM
, 0x009b, 0x04fc); // DCO1_HI
791 msp_writereg(av7110
, MSP_WR_DEM
, 0x00a3, 0x038e); // DCO2_LO 5.5MHz
792 msp_writereg(av7110
, MSP_WR_DEM
, 0x00ab, 0x04c6); // DCO2_HI
793 msp_writereg(av7110
, MSP_WR_DEM
, 0x0056, 0); // LOAD_REG 1/2
796 memcpy(standard
, dvb_standard
, sizeof(struct saa7146_standard
) * 2);
797 /* set dd1 stream a & b */
798 saa7146_write(av7110
->dev
, DD1_STREAM_B
, 0x00000000);
799 saa7146_write(av7110
->dev
, DD1_INIT
, 0x03000700);
800 saa7146_write(av7110
->dev
, MC2
, (MASK_09
| MASK_25
| MASK_10
| MASK_26
));
805 int av7110_init_v4l(struct av7110
*av7110
)
807 struct saa7146_dev
* dev
= av7110
->dev
;
808 struct saa7146_ext_vv
*vv_data
;
811 /* special case DVB-C: these cards have an analog tuner
812 plus need some special handling, so we have separate
813 saa7146_ext_vv data for these... */
814 if (av7110
->analog_tuner_flags
)
815 vv_data
= &av7110_vv_data_c
;
817 vv_data
= &av7110_vv_data_st
;
818 ret
= saa7146_vv_init(dev
, vv_data
);
821 ERR("cannot init capture device. skipping\n");
824 vv_data
->vid_ops
.vidioc_enum_input
= vidioc_enum_input
;
825 vv_data
->vid_ops
.vidioc_g_input
= vidioc_g_input
;
826 vv_data
->vid_ops
.vidioc_s_input
= vidioc_s_input
;
827 vv_data
->vid_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
828 vv_data
->vid_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
829 vv_data
->vid_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
830 vv_data
->vid_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
831 vv_data
->vid_ops
.vidioc_enumaudio
= vidioc_enumaudio
;
832 vv_data
->vid_ops
.vidioc_g_audio
= vidioc_g_audio
;
833 vv_data
->vid_ops
.vidioc_s_audio
= vidioc_s_audio
;
834 vv_data
->vid_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
836 vv_data
->vbi_ops
.vidioc_g_tuner
= vidioc_g_tuner
;
837 vv_data
->vbi_ops
.vidioc_s_tuner
= vidioc_s_tuner
;
838 vv_data
->vbi_ops
.vidioc_g_frequency
= vidioc_g_frequency
;
839 vv_data
->vbi_ops
.vidioc_s_frequency
= vidioc_s_frequency
;
840 vv_data
->vbi_ops
.vidioc_g_fmt_vbi_cap
= NULL
;
841 vv_data
->vbi_ops
.vidioc_g_sliced_vbi_cap
= vidioc_g_sliced_vbi_cap
;
842 vv_data
->vbi_ops
.vidioc_g_fmt_sliced_vbi_out
= vidioc_g_fmt_sliced_vbi_out
;
843 vv_data
->vbi_ops
.vidioc_s_fmt_sliced_vbi_out
= vidioc_s_fmt_sliced_vbi_out
;
845 if (FW_VERSION(av7110
->arm_app
) < 0x2623)
846 vv_data
->capabilities
&= ~V4L2_CAP_SLICED_VBI_OUTPUT
;
848 if (saa7146_register_device(&av7110
->v4l_dev
, dev
, "av7110", VFL_TYPE_GRABBER
)) {
849 ERR("cannot register capture device. skipping\n");
850 saa7146_vv_release(dev
);
853 if (FW_VERSION(av7110
->arm_app
) >= 0x2623) {
854 if (saa7146_register_device(&av7110
->vbi_dev
, dev
, "av7110", VFL_TYPE_VBI
))
855 ERR("cannot register vbi v4l2 device. skipping\n");
860 int av7110_exit_v4l(struct av7110
*av7110
)
862 struct saa7146_dev
* dev
= av7110
->dev
;
864 saa7146_unregister_device(&av7110
->v4l_dev
, av7110
->dev
);
865 saa7146_unregister_device(&av7110
->vbi_dev
, av7110
->dev
);
867 saa7146_vv_release(dev
);
874 /* FIXME: these values are experimental values that look better than the
875 values from the latest "official" driver -- at least for me... (MiHu) */
876 static struct saa7146_standard standard
[] = {
878 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
879 .v_offset
= 0x15, .v_field
= 288,
880 .h_offset
= 0x48, .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 analog_standard
[] = {
892 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
893 .v_offset
= 0x1b, .v_field
= 288,
894 .h_offset
= 0x08, .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 struct saa7146_standard dvb_standard
[] = {
906 .name
= "PAL", .id
= V4L2_STD_PAL_BG
,
907 .v_offset
= 0x14, .v_field
= 288,
908 .h_offset
= 0x48, .h_pixels
= 708,
909 .v_max_out
= 576, .h_max_out
= 768,
911 .name
= "NTSC", .id
= V4L2_STD_NTSC
,
912 .v_offset
= 0x10, .v_field
= 244,
913 .h_offset
= 0x40, .h_pixels
= 708,
914 .v_max_out
= 480, .h_max_out
= 640,
918 static int std_callback(struct saa7146_dev
* dev
, struct saa7146_standard
*std
)
920 struct av7110
*av7110
= (struct av7110
*) dev
->ext_priv
;
922 if (std
->id
& V4L2_STD_PAL
) {
923 av7110
->vidmode
= AV7110_VIDEO_MODE_PAL
;
924 av7110_set_vidmode(av7110
, av7110
->vidmode
);
926 else if (std
->id
& V4L2_STD_NTSC
) {
927 av7110
->vidmode
= AV7110_VIDEO_MODE_NTSC
;
928 av7110_set_vidmode(av7110
, av7110
->vidmode
);
937 static struct saa7146_ext_vv av7110_vv_data_st
= {
940 .capabilities
= V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
943 .stds
= &standard
[0],
944 .num_stds
= ARRAY_SIZE(standard
),
945 .std_callback
= &std_callback
,
947 .vbi_fops
.open
= av7110_vbi_reset
,
948 .vbi_fops
.release
= av7110_vbi_reset
,
949 .vbi_fops
.write
= av7110_vbi_write
,
952 static struct saa7146_ext_vv av7110_vv_data_c
= {
955 .capabilities
= V4L2_CAP_TUNER
| V4L2_CAP_SLICED_VBI_OUTPUT
| V4L2_CAP_AUDIO
,
956 .flags
= SAA7146_USE_PORT_B_FOR_VBI
,
958 .stds
= &standard
[0],
959 .num_stds
= ARRAY_SIZE(standard
),
960 .std_callback
= &std_callback
,
962 .vbi_fops
.open
= av7110_vbi_reset
,
963 .vbi_fops
.release
= av7110_vbi_reset
,
964 .vbi_fops
.write
= av7110_vbi_write
,