2 * Driver for the NXP SAA7164 PCIe bridge
4 * Copyright (c) 2010 Steven Toth <stoth@kernellabs.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define ENCODER_MAX_BITRATE 6500000
25 #define ENCODER_MIN_BITRATE 1000000
26 #define ENCODER_DEF_BITRATE 5000000
28 static struct saa7164_tvnorm saa7164_tvnorms
[] = {
31 .id
= V4L2_STD_NTSC_M
,
34 .id
= V4L2_STD_NTSC_M_JP
,
38 static const u32 saa7164_v4l2_ctrls
[] = {
43 V4L2_CID_AUDIO_VOLUME
,
45 V4L2_CID_MPEG_STREAM_TYPE
,
46 V4L2_CID_MPEG_VIDEO_ASPECT
,
47 V4L2_CID_MPEG_VIDEO_B_FRAMES
,
48 V4L2_CID_MPEG_VIDEO_GOP_SIZE
,
49 V4L2_CID_MPEG_AUDIO_MUTE
,
50 V4L2_CID_MPEG_VIDEO_BITRATE_MODE
,
51 V4L2_CID_MPEG_VIDEO_BITRATE
,
52 V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
,
56 /* Take the encoder configuration form the port struct and
57 * flush it to the hardware.
59 static void saa7164_encoder_configure(struct saa7164_port
*port
)
61 struct saa7164_dev
*dev
= port
->dev
;
62 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
64 port
->encoder_params
.width
= port
->width
;
65 port
->encoder_params
.height
= port
->height
;
66 port
->encoder_params
.is_50hz
=
67 (port
->encodernorm
.id
& V4L2_STD_625_50
) != 0;
69 /* Set up the DIF (enable it) for analog mode by default */
70 saa7164_api_initialize_dif(port
);
72 /* Configure the correct video standard */
73 saa7164_api_configure_dif(port
, port
->encodernorm
.id
);
75 /* Ensure the audio decoder is correct configured */
76 saa7164_api_set_audio_std(port
);
79 static int saa7164_encoder_buffers_dealloc(struct saa7164_port
*port
)
81 struct list_head
*c
, *n
, *p
, *q
, *l
, *v
;
82 struct saa7164_dev
*dev
= port
->dev
;
83 struct saa7164_buffer
*buf
;
84 struct saa7164_user_buffer
*ubuf
;
86 /* Remove any allocated buffers */
87 mutex_lock(&port
->dmaqueue_lock
);
89 dprintk(DBGLVL_ENC
, "%s(port=%d) dmaqueue\n", __func__
, port
->nr
);
90 list_for_each_safe(c
, n
, &port
->dmaqueue
.list
) {
91 buf
= list_entry(c
, struct saa7164_buffer
, list
);
93 saa7164_buffer_dealloc(buf
);
96 dprintk(DBGLVL_ENC
, "%s(port=%d) used\n", __func__
, port
->nr
);
97 list_for_each_safe(p
, q
, &port
->list_buf_used
.list
) {
98 ubuf
= list_entry(p
, struct saa7164_user_buffer
, list
);
100 saa7164_buffer_dealloc_user(ubuf
);
103 dprintk(DBGLVL_ENC
, "%s(port=%d) free\n", __func__
, port
->nr
);
104 list_for_each_safe(l
, v
, &port
->list_buf_free
.list
) {
105 ubuf
= list_entry(l
, struct saa7164_user_buffer
, list
);
107 saa7164_buffer_dealloc_user(ubuf
);
110 mutex_unlock(&port
->dmaqueue_lock
);
111 dprintk(DBGLVL_ENC
, "%s(port=%d) done\n", __func__
, port
->nr
);
116 /* Dynamic buffer switch at encoder start time */
117 static int saa7164_encoder_buffers_alloc(struct saa7164_port
*port
)
119 struct saa7164_dev
*dev
= port
->dev
;
120 struct saa7164_buffer
*buf
;
121 struct saa7164_user_buffer
*ubuf
;
122 struct tmHWStreamParameters
*params
= &port
->hw_streamingparams
;
123 int result
= -ENODEV
, i
;
126 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
128 if (port
->encoder_params
.stream_type
==
129 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
) {
131 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_PS\n",
133 params
->samplesperline
= 128;
134 params
->numberoflines
= 256;
136 params
->numpagetables
= 2 +
137 ((SAA7164_PS_NUMBER_OF_LINES
* 128) / PAGE_SIZE
);
139 if (port
->encoder_params
.stream_type
==
140 V4L2_MPEG_STREAM_TYPE_MPEG2_TS
) {
142 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_TS\n",
144 params
->samplesperline
= 188;
145 params
->numberoflines
= 312;
147 params
->numpagetables
= 2 +
148 ((SAA7164_TS_NUMBER_OF_LINES
* 188) / PAGE_SIZE
);
152 /* Init and establish defaults */
153 params
->bitspersample
= 8;
154 params
->linethreshold
= 0;
155 params
->pagetablelistvirt
= NULL
;
156 params
->pagetablelistphys
= NULL
;
157 params
->numpagetableentries
= port
->hwcfg
.buffercount
;
159 /* Allocate the PCI resources, buffers (hard) */
160 for (i
= 0; i
< port
->hwcfg
.buffercount
; i
++) {
161 buf
= saa7164_buffer_alloc(port
,
162 params
->numberoflines
*
166 printk(KERN_ERR
"%s() failed "
167 "(errno = %d), unable to allocate buffer\n",
173 mutex_lock(&port
->dmaqueue_lock
);
174 list_add_tail(&buf
->list
, &port
->dmaqueue
.list
);
175 mutex_unlock(&port
->dmaqueue_lock
);
180 /* Allocate some kernel buffers for copying
183 len
= params
->numberoflines
* params
->pitch
;
185 if (encoder_buffers
< 16)
186 encoder_buffers
= 16;
187 if (encoder_buffers
> 512)
188 encoder_buffers
= 512;
190 for (i
= 0; i
< encoder_buffers
; i
++) {
192 ubuf
= saa7164_buffer_alloc_user(dev
, len
);
194 mutex_lock(&port
->dmaqueue_lock
);
195 list_add_tail(&ubuf
->list
, &port
->list_buf_free
.list
);
196 mutex_unlock(&port
->dmaqueue_lock
);
207 static int saa7164_encoder_initialize(struct saa7164_port
*port
)
209 saa7164_encoder_configure(port
);
213 /* -- V4L2 --------------------------------------------------------- */
214 static int vidioc_s_std(struct file
*file
, void *priv
, v4l2_std_id
*id
)
216 struct saa7164_encoder_fh
*fh
= file
->private_data
;
217 struct saa7164_port
*port
= fh
->port
;
218 struct saa7164_dev
*dev
= port
->dev
;
221 dprintk(DBGLVL_ENC
, "%s(id=0x%x)\n", __func__
, (u32
)*id
);
223 for (i
= 0; i
< ARRAY_SIZE(saa7164_tvnorms
); i
++) {
224 if (*id
& saa7164_tvnorms
[i
].id
)
227 if (i
== ARRAY_SIZE(saa7164_tvnorms
))
230 port
->encodernorm
= saa7164_tvnorms
[i
];
232 /* Update the audio decoder while is not running in
235 saa7164_api_set_audio_std(port
);
237 dprintk(DBGLVL_ENC
, "%s(id=0x%x) OK\n", __func__
, (u32
)*id
);
242 static int vidioc_enum_input(struct file
*file
, void *priv
,
243 struct v4l2_input
*i
)
247 char *inputs
[] = { "tuner", "composite", "svideo", "aux",
248 "composite 2", "svideo 2", "aux 2" };
253 strcpy(i
->name
, inputs
[i
->index
]);
256 i
->type
= V4L2_INPUT_TYPE_TUNER
;
258 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
260 for (n
= 0; n
< ARRAY_SIZE(saa7164_tvnorms
); n
++)
261 i
->std
|= saa7164_tvnorms
[n
].id
;
266 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
268 struct saa7164_encoder_fh
*fh
= file
->private_data
;
269 struct saa7164_port
*port
= fh
->port
;
270 struct saa7164_dev
*dev
= port
->dev
;
272 if (saa7164_api_get_videomux(port
) != SAA_OK
)
275 *i
= (port
->mux_input
- 1);
277 dprintk(DBGLVL_ENC
, "%s() input=%d\n", __func__
, *i
);
282 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
284 struct saa7164_encoder_fh
*fh
= file
->private_data
;
285 struct saa7164_port
*port
= fh
->port
;
286 struct saa7164_dev
*dev
= port
->dev
;
288 dprintk(DBGLVL_ENC
, "%s() input=%d\n", __func__
, i
);
293 port
->mux_input
= i
+ 1;
295 if (saa7164_api_set_videomux(port
) != SAA_OK
)
301 static int vidioc_g_tuner(struct file
*file
, void *priv
,
302 struct v4l2_tuner
*t
)
304 struct saa7164_encoder_fh
*fh
= file
->private_data
;
305 struct saa7164_port
*port
= fh
->port
;
306 struct saa7164_dev
*dev
= port
->dev
;
311 strcpy(t
->name
, "tuner");
312 t
->type
= V4L2_TUNER_ANALOG_TV
;
313 t
->capability
= V4L2_TUNER_CAP_NORM
| V4L2_TUNER_CAP_STEREO
;
315 dprintk(DBGLVL_ENC
, "VIDIOC_G_TUNER: tuner type %d\n", t
->type
);
320 static int vidioc_s_tuner(struct file
*file
, void *priv
,
321 struct v4l2_tuner
*t
)
323 /* Update the A/V core */
327 static int vidioc_g_frequency(struct file
*file
, void *priv
,
328 struct v4l2_frequency
*f
)
330 struct saa7164_encoder_fh
*fh
= file
->private_data
;
331 struct saa7164_port
*port
= fh
->port
;
333 f
->type
= V4L2_TUNER_ANALOG_TV
;
334 f
->frequency
= port
->freq
;
339 static int vidioc_s_frequency(struct file
*file
, void *priv
,
340 struct v4l2_frequency
*f
)
342 struct saa7164_encoder_fh
*fh
= file
->private_data
;
343 struct saa7164_port
*port
= fh
->port
;
344 struct saa7164_dev
*dev
= port
->dev
;
345 struct saa7164_port
*tsport
;
346 struct dvb_frontend
*fe
;
348 /* TODO: Pull this for the std */
349 struct analog_parameters params
= {
350 .mode
= V4L2_TUNER_ANALOG_TV
,
351 .audmode
= V4L2_TUNER_MODE_STEREO
,
352 .std
= port
->encodernorm
.id
,
353 .frequency
= f
->frequency
356 /* Stop the encoder */
357 dprintk(DBGLVL_ENC
, "%s() frequency=%d tuner=%d\n", __func__
,
358 f
->frequency
, f
->tuner
);
363 if (f
->type
!= V4L2_TUNER_ANALOG_TV
)
366 port
->freq
= f
->frequency
;
368 /* Update the hardware */
369 if (port
->nr
== SAA7164_PORT_ENC1
)
370 tsport
= &dev
->ports
[SAA7164_PORT_TS1
];
372 if (port
->nr
== SAA7164_PORT_ENC2
)
373 tsport
= &dev
->ports
[SAA7164_PORT_TS2
];
377 fe
= tsport
->dvb
.frontend
;
379 if (fe
&& fe
->ops
.tuner_ops
.set_analog_params
)
380 fe
->ops
.tuner_ops
.set_analog_params(fe
, ¶ms
);
382 printk(KERN_ERR
"%s() No analog tuner, aborting\n", __func__
);
384 saa7164_encoder_initialize(port
);
389 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
390 struct v4l2_control
*ctl
)
392 struct saa7164_encoder_fh
*fh
= file
->private_data
;
393 struct saa7164_port
*port
= fh
->port
;
394 struct saa7164_dev
*dev
= port
->dev
;
396 dprintk(DBGLVL_ENC
, "%s(id=%d, value=%d)\n", __func__
,
397 ctl
->id
, ctl
->value
);
400 case V4L2_CID_BRIGHTNESS
:
401 ctl
->value
= port
->ctl_brightness
;
403 case V4L2_CID_CONTRAST
:
404 ctl
->value
= port
->ctl_contrast
;
406 case V4L2_CID_SATURATION
:
407 ctl
->value
= port
->ctl_saturation
;
410 ctl
->value
= port
->ctl_hue
;
412 case V4L2_CID_SHARPNESS
:
413 ctl
->value
= port
->ctl_sharpness
;
415 case V4L2_CID_AUDIO_VOLUME
:
416 ctl
->value
= port
->ctl_volume
;
425 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
426 struct v4l2_control
*ctl
)
428 struct saa7164_encoder_fh
*fh
= file
->private_data
;
429 struct saa7164_port
*port
= fh
->port
;
430 struct saa7164_dev
*dev
= port
->dev
;
433 dprintk(DBGLVL_ENC
, "%s(id=%d, value=%d)\n", __func__
,
434 ctl
->id
, ctl
->value
);
437 case V4L2_CID_BRIGHTNESS
:
438 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
439 port
->ctl_brightness
= ctl
->value
;
440 saa7164_api_set_usercontrol(port
,
441 PU_BRIGHTNESS_CONTROL
);
445 case V4L2_CID_CONTRAST
:
446 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
447 port
->ctl_contrast
= ctl
->value
;
448 saa7164_api_set_usercontrol(port
, PU_CONTRAST_CONTROL
);
452 case V4L2_CID_SATURATION
:
453 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
454 port
->ctl_saturation
= ctl
->value
;
455 saa7164_api_set_usercontrol(port
,
456 PU_SATURATION_CONTROL
);
461 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
462 port
->ctl_hue
= ctl
->value
;
463 saa7164_api_set_usercontrol(port
, PU_HUE_CONTROL
);
467 case V4L2_CID_SHARPNESS
:
468 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
469 port
->ctl_sharpness
= ctl
->value
;
470 saa7164_api_set_usercontrol(port
, PU_SHARPNESS_CONTROL
);
474 case V4L2_CID_AUDIO_VOLUME
:
475 if ((ctl
->value
>= -83) && (ctl
->value
<= 24)) {
476 port
->ctl_volume
= ctl
->value
;
477 saa7164_api_set_audio_volume(port
, port
->ctl_volume
);
488 static int saa7164_get_ctrl(struct saa7164_port
*port
,
489 struct v4l2_ext_control
*ctrl
)
491 struct saa7164_encoder_params
*params
= &port
->encoder_params
;
494 case V4L2_CID_MPEG_VIDEO_BITRATE
:
495 ctrl
->value
= params
->bitrate
;
497 case V4L2_CID_MPEG_STREAM_TYPE
:
498 ctrl
->value
= params
->stream_type
;
500 case V4L2_CID_MPEG_AUDIO_MUTE
:
501 ctrl
->value
= params
->ctl_mute
;
503 case V4L2_CID_MPEG_VIDEO_ASPECT
:
504 ctrl
->value
= params
->ctl_aspect
;
506 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
507 ctrl
->value
= params
->bitrate_mode
;
509 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
510 ctrl
->value
= params
->refdist
;
512 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
513 ctrl
->value
= params
->bitrate_peak
;
515 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
516 ctrl
->value
= params
->gop_size
;
524 static int vidioc_g_ext_ctrls(struct file
*file
, void *priv
,
525 struct v4l2_ext_controls
*ctrls
)
527 struct saa7164_encoder_fh
*fh
= file
->private_data
;
528 struct saa7164_port
*port
= fh
->port
;
531 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
532 for (i
= 0; i
< ctrls
->count
; i
++) {
533 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
535 err
= saa7164_get_ctrl(port
, ctrl
);
537 ctrls
->error_idx
= i
;
548 static int saa7164_try_ctrl(struct v4l2_ext_control
*ctrl
, int ac3
)
553 case V4L2_CID_MPEG_VIDEO_BITRATE
:
554 if ((ctrl
->value
>= ENCODER_MIN_BITRATE
) &&
555 (ctrl
->value
<= ENCODER_MAX_BITRATE
))
558 case V4L2_CID_MPEG_STREAM_TYPE
:
559 if ((ctrl
->value
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
) ||
560 (ctrl
->value
== V4L2_MPEG_STREAM_TYPE_MPEG2_TS
))
563 case V4L2_CID_MPEG_AUDIO_MUTE
:
564 if ((ctrl
->value
>= 0) &&
568 case V4L2_CID_MPEG_VIDEO_ASPECT
:
569 if ((ctrl
->value
>= V4L2_MPEG_VIDEO_ASPECT_1x1
) &&
570 (ctrl
->value
<= V4L2_MPEG_VIDEO_ASPECT_221x100
))
573 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
574 if ((ctrl
->value
>= 0) &&
575 (ctrl
->value
<= 255))
578 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
579 if ((ctrl
->value
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
) ||
580 (ctrl
->value
== V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
))
583 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
584 if ((ctrl
->value
>= 1) &&
588 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
589 if ((ctrl
->value
>= ENCODER_MIN_BITRATE
) &&
590 (ctrl
->value
<= ENCODER_MAX_BITRATE
))
600 static int vidioc_try_ext_ctrls(struct file
*file
, void *priv
,
601 struct v4l2_ext_controls
*ctrls
)
605 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
606 for (i
= 0; i
< ctrls
->count
; i
++) {
607 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
609 err
= saa7164_try_ctrl(ctrl
, 0);
611 ctrls
->error_idx
= i
;
621 static int saa7164_set_ctrl(struct saa7164_port
*port
,
622 struct v4l2_ext_control
*ctrl
)
624 struct saa7164_encoder_params
*params
= &port
->encoder_params
;
628 case V4L2_CID_MPEG_VIDEO_BITRATE
:
629 params
->bitrate
= ctrl
->value
;
631 case V4L2_CID_MPEG_STREAM_TYPE
:
632 params
->stream_type
= ctrl
->value
;
634 case V4L2_CID_MPEG_AUDIO_MUTE
:
635 params
->ctl_mute
= ctrl
->value
;
636 ret
= saa7164_api_audio_mute(port
, params
->ctl_mute
);
638 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
643 case V4L2_CID_MPEG_VIDEO_ASPECT
:
644 params
->ctl_aspect
= ctrl
->value
;
645 ret
= saa7164_api_set_aspect_ratio(port
);
647 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
652 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
653 params
->bitrate_mode
= ctrl
->value
;
655 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
656 params
->refdist
= ctrl
->value
;
658 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
659 params
->bitrate_peak
= ctrl
->value
;
661 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
662 params
->gop_size
= ctrl
->value
;
668 /* TODO: Update the hardware */
673 static int vidioc_s_ext_ctrls(struct file
*file
, void *priv
,
674 struct v4l2_ext_controls
*ctrls
)
676 struct saa7164_encoder_fh
*fh
= file
->private_data
;
677 struct saa7164_port
*port
= fh
->port
;
680 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
681 for (i
= 0; i
< ctrls
->count
; i
++) {
682 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
684 err
= saa7164_try_ctrl(ctrl
, 0);
686 ctrls
->error_idx
= i
;
689 err
= saa7164_set_ctrl(port
, ctrl
);
691 ctrls
->error_idx
= i
;
702 static int vidioc_querycap(struct file
*file
, void *priv
,
703 struct v4l2_capability
*cap
)
705 struct saa7164_encoder_fh
*fh
= file
->private_data
;
706 struct saa7164_port
*port
= fh
->port
;
707 struct saa7164_dev
*dev
= port
->dev
;
709 strcpy(cap
->driver
, dev
->name
);
710 strlcpy(cap
->card
, saa7164_boards
[dev
->board
].name
,
712 sprintf(cap
->bus_info
, "PCI:%s", pci_name(dev
->pci
));
715 V4L2_CAP_VIDEO_CAPTURE
|
719 cap
->capabilities
|= V4L2_CAP_TUNER
;
725 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
726 struct v4l2_fmtdesc
*f
)
731 strlcpy(f
->description
, "MPEG", sizeof(f
->description
));
732 f
->pixelformat
= V4L2_PIX_FMT_MPEG
;
737 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
738 struct v4l2_format
*f
)
740 struct saa7164_encoder_fh
*fh
= file
->private_data
;
741 struct saa7164_port
*port
= fh
->port
;
742 struct saa7164_dev
*dev
= port
->dev
;
744 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
745 f
->fmt
.pix
.bytesperline
= 0;
746 f
->fmt
.pix
.sizeimage
=
747 port
->ts_packet_size
* port
->ts_packet_count
;
748 f
->fmt
.pix
.colorspace
= 0;
749 f
->fmt
.pix
.width
= port
->width
;
750 f
->fmt
.pix
.height
= port
->height
;
752 dprintk(DBGLVL_ENC
, "VIDIOC_G_FMT: w: %d, h: %d\n",
753 port
->width
, port
->height
);
758 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
759 struct v4l2_format
*f
)
761 struct saa7164_encoder_fh
*fh
= file
->private_data
;
762 struct saa7164_port
*port
= fh
->port
;
763 struct saa7164_dev
*dev
= port
->dev
;
765 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
766 f
->fmt
.pix
.bytesperline
= 0;
767 f
->fmt
.pix
.sizeimage
=
768 port
->ts_packet_size
* port
->ts_packet_count
;
769 f
->fmt
.pix
.colorspace
= 0;
770 dprintk(DBGLVL_ENC
, "VIDIOC_TRY_FMT: w: %d, h: %d\n",
771 port
->width
, port
->height
);
775 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
776 struct v4l2_format
*f
)
778 struct saa7164_encoder_fh
*fh
= file
->private_data
;
779 struct saa7164_port
*port
= fh
->port
;
780 struct saa7164_dev
*dev
= port
->dev
;
782 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
783 f
->fmt
.pix
.bytesperline
= 0;
784 f
->fmt
.pix
.sizeimage
=
785 port
->ts_packet_size
* port
->ts_packet_count
;
786 f
->fmt
.pix
.colorspace
= 0;
788 dprintk(DBGLVL_ENC
, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
789 f
->fmt
.pix
.width
, f
->fmt
.pix
.height
, f
->fmt
.pix
.field
);
794 static int vidioc_log_status(struct file
*file
, void *priv
)
799 static int fill_queryctrl(struct saa7164_encoder_params
*params
,
800 struct v4l2_queryctrl
*c
)
803 case V4L2_CID_BRIGHTNESS
:
804 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 127);
805 case V4L2_CID_CONTRAST
:
806 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 66);
807 case V4L2_CID_SATURATION
:
808 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 62);
810 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 128);
811 case V4L2_CID_SHARPNESS
:
812 return v4l2_ctrl_query_fill(c
, 0x0, 0x0f, 1, 8);
813 case V4L2_CID_MPEG_AUDIO_MUTE
:
814 return v4l2_ctrl_query_fill(c
, 0x0, 0x01, 1, 0);
815 case V4L2_CID_AUDIO_VOLUME
:
816 return v4l2_ctrl_query_fill(c
, -83, 24, 1, 20);
817 case V4L2_CID_MPEG_VIDEO_BITRATE
:
818 return v4l2_ctrl_query_fill(c
,
819 ENCODER_MIN_BITRATE
, ENCODER_MAX_BITRATE
,
820 100000, ENCODER_DEF_BITRATE
);
821 case V4L2_CID_MPEG_STREAM_TYPE
:
822 return v4l2_ctrl_query_fill(c
,
823 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
,
824 V4L2_MPEG_STREAM_TYPE_MPEG2_TS
,
825 1, V4L2_MPEG_STREAM_TYPE_MPEG2_PS
);
826 case V4L2_CID_MPEG_VIDEO_ASPECT
:
827 return v4l2_ctrl_query_fill(c
,
828 V4L2_MPEG_VIDEO_ASPECT_1x1
,
829 V4L2_MPEG_VIDEO_ASPECT_221x100
,
830 1, V4L2_MPEG_VIDEO_ASPECT_4x3
);
831 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
832 return v4l2_ctrl_query_fill(c
, 1, 255, 1, 15);
833 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
834 return v4l2_ctrl_query_fill(c
,
835 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
,
836 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
,
837 1, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
838 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
839 return v4l2_ctrl_query_fill(c
,
841 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
842 return v4l2_ctrl_query_fill(c
,
843 ENCODER_MIN_BITRATE
, ENCODER_MAX_BITRATE
,
844 100000, ENCODER_DEF_BITRATE
);
850 static int vidioc_queryctrl(struct file
*file
, void *priv
,
851 struct v4l2_queryctrl
*c
)
853 struct saa7164_encoder_fh
*fh
= priv
;
854 struct saa7164_port
*port
= fh
->port
;
858 memset(c
, 0, sizeof(*c
));
860 next
= !!(id
& V4L2_CTRL_FLAG_NEXT_CTRL
);
861 c
->id
= id
& ~V4L2_CTRL_FLAG_NEXT_CTRL
;
863 for (i
= 0; i
< ARRAY_SIZE(saa7164_v4l2_ctrls
); i
++) {
865 if (c
->id
< saa7164_v4l2_ctrls
[i
])
866 c
->id
= saa7164_v4l2_ctrls
[i
];
871 if (c
->id
== saa7164_v4l2_ctrls
[i
])
872 return fill_queryctrl(&port
->encoder_params
, c
);
874 if (c
->id
< saa7164_v4l2_ctrls
[i
])
881 static int saa7164_encoder_stop_port(struct saa7164_port
*port
)
883 struct saa7164_dev
*dev
= port
->dev
;
886 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
887 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
888 printk(KERN_ERR
"%s() stop transition failed, ret = 0x%x\n",
892 dprintk(DBGLVL_ENC
, "%s() Stopped\n", __func__
);
899 static int saa7164_encoder_acquire_port(struct saa7164_port
*port
)
901 struct saa7164_dev
*dev
= port
->dev
;
904 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_ACQUIRE
);
905 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
906 printk(KERN_ERR
"%s() acquire transition failed, ret = 0x%x\n",
910 dprintk(DBGLVL_ENC
, "%s() Acquired\n", __func__
);
917 static int saa7164_encoder_pause_port(struct saa7164_port
*port
)
919 struct saa7164_dev
*dev
= port
->dev
;
922 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_PAUSE
);
923 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
924 printk(KERN_ERR
"%s() pause transition failed, ret = 0x%x\n",
928 dprintk(DBGLVL_ENC
, "%s() Paused\n", __func__
);
935 /* Firmware is very windows centric, meaning you have to transition
936 * the part through AVStream / KS Windows stages, forwards or backwards.
937 * States are: stopped, acquired (h/w), paused, started.
938 * We have to leave here will all of the soft buffers on the free list,
939 * else the cfg_post() func won't have soft buffers to correctly configure.
941 static int saa7164_encoder_stop_streaming(struct saa7164_port
*port
)
943 struct saa7164_dev
*dev
= port
->dev
;
944 struct saa7164_buffer
*buf
;
945 struct saa7164_user_buffer
*ubuf
;
946 struct list_head
*c
, *n
;
949 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
951 ret
= saa7164_encoder_pause_port(port
);
952 ret
= saa7164_encoder_acquire_port(port
);
953 ret
= saa7164_encoder_stop_port(port
);
955 dprintk(DBGLVL_ENC
, "%s(port=%d) Hardware stopped\n", __func__
,
958 /* Reset the state of any allocated buffer resources */
959 mutex_lock(&port
->dmaqueue_lock
);
961 /* Reset the hard and soft buffer state */
962 list_for_each_safe(c
, n
, &port
->dmaqueue
.list
) {
963 buf
= list_entry(c
, struct saa7164_buffer
, list
);
964 buf
->flags
= SAA7164_BUFFER_FREE
;
968 list_for_each_safe(c
, n
, &port
->list_buf_used
.list
) {
969 ubuf
= list_entry(c
, struct saa7164_user_buffer
, list
);
971 list_move_tail(&ubuf
->list
, &port
->list_buf_free
.list
);
974 mutex_unlock(&port
->dmaqueue_lock
);
976 /* Free any allocated resources */
977 saa7164_encoder_buffers_dealloc(port
);
979 dprintk(DBGLVL_ENC
, "%s(port=%d) Released\n", __func__
, port
->nr
);
984 static int saa7164_encoder_start_streaming(struct saa7164_port
*port
)
986 struct saa7164_dev
*dev
= port
->dev
;
989 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
991 port
->done_first_interrupt
= 0;
993 /* allocate all of the PCIe DMA buffer resources on the fly,
994 * allowing switching between TS and PS payloads without
995 * requiring a complete driver reload.
997 saa7164_encoder_buffers_alloc(port
);
999 /* Configure the encoder with any cache values */
1000 saa7164_api_set_encoder(port
);
1001 saa7164_api_get_encoder(port
);
1003 /* Place the empty buffers on the hardware */
1004 saa7164_buffer_cfg_port(port
);
1006 /* Acquire the hardware */
1007 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_ACQUIRE
);
1008 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1009 printk(KERN_ERR
"%s() acquire transition failed, res = 0x%x\n",
1012 /* Stop the hardware, regardless */
1013 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1014 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1015 printk(KERN_ERR
"%s() acquire/forced stop transition "
1016 "failed, res = 0x%x\n", __func__
, result
);
1021 dprintk(DBGLVL_ENC
, "%s() Acquired\n", __func__
);
1023 /* Pause the hardware */
1024 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_PAUSE
);
1025 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1026 printk(KERN_ERR
"%s() pause transition failed, res = 0x%x\n",
1029 /* Stop the hardware, regardless */
1030 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1031 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1032 printk(KERN_ERR
"%s() pause/forced stop transition "
1033 "failed, res = 0x%x\n", __func__
, result
);
1039 dprintk(DBGLVL_ENC
, "%s() Paused\n", __func__
);
1041 /* Start the hardware */
1042 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_RUN
);
1043 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1044 printk(KERN_ERR
"%s() run transition failed, result = 0x%x\n",
1047 /* Stop the hardware, regardless */
1048 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1049 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1050 printk(KERN_ERR
"%s() run/forced stop transition "
1051 "failed, res = 0x%x\n", __func__
, result
);
1056 dprintk(DBGLVL_ENC
, "%s() Running\n", __func__
);
1062 static int fops_open(struct file
*file
)
1064 struct saa7164_dev
*dev
;
1065 struct saa7164_port
*port
;
1066 struct saa7164_encoder_fh
*fh
;
1068 port
= (struct saa7164_port
*)video_get_drvdata(video_devdata(file
));
1074 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1076 /* allocate + initialize per filehandle data */
1077 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1081 file
->private_data
= fh
;
1087 static int fops_release(struct file
*file
)
1089 struct saa7164_encoder_fh
*fh
= file
->private_data
;
1090 struct saa7164_port
*port
= fh
->port
;
1091 struct saa7164_dev
*dev
= port
->dev
;
1093 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1095 /* Shut device down on last close */
1096 if (atomic_cmpxchg(&fh
->v4l_reading
, 1, 0) == 1) {
1097 if (atomic_dec_return(&port
->v4l_reader_count
) == 0) {
1098 /* stop mpeg capture then cancel buffers */
1099 saa7164_encoder_stop_streaming(port
);
1103 file
->private_data
= NULL
;
1109 struct saa7164_user_buffer
*saa7164_enc_next_buf(struct saa7164_port
*port
)
1111 struct saa7164_user_buffer
*ubuf
= NULL
;
1112 struct saa7164_dev
*dev
= port
->dev
;
1115 mutex_lock(&port
->dmaqueue_lock
);
1116 if (!list_empty(&port
->list_buf_used
.list
)) {
1117 ubuf
= list_first_entry(&port
->list_buf_used
.list
,
1118 struct saa7164_user_buffer
, list
);
1121 crc
= crc32(0, ubuf
->data
, ubuf
->actual_size
);
1122 if (crc
!= ubuf
->crc
) {
1124 "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n",
1126 ubuf
, ubuf
->crc
, crc
);
1131 mutex_unlock(&port
->dmaqueue_lock
);
1133 dprintk(DBGLVL_ENC
, "%s() returns %p\n", __func__
, ubuf
);
1138 static ssize_t
fops_read(struct file
*file
, char __user
*buffer
,
1139 size_t count
, loff_t
*pos
)
1141 struct saa7164_encoder_fh
*fh
= file
->private_data
;
1142 struct saa7164_port
*port
= fh
->port
;
1143 struct saa7164_user_buffer
*ubuf
= NULL
;
1144 struct saa7164_dev
*dev
= port
->dev
;
1149 port
->last_read_msecs_diff
= port
->last_read_msecs
;
1150 port
->last_read_msecs
= jiffies_to_msecs(jiffies
);
1151 port
->last_read_msecs_diff
= port
->last_read_msecs
-
1152 port
->last_read_msecs_diff
;
1154 saa7164_histogram_update(&port
->read_interval
,
1155 port
->last_read_msecs_diff
);
1158 printk(KERN_ERR
"%s() ESPIPE\n", __func__
);
1162 if (atomic_cmpxchg(&fh
->v4l_reading
, 0, 1) == 0) {
1163 if (atomic_inc_return(&port
->v4l_reader_count
) == 1) {
1165 if (saa7164_encoder_initialize(port
) < 0) {
1166 printk(KERN_ERR
"%s() EINVAL\n", __func__
);
1170 saa7164_encoder_start_streaming(port
);
1175 /* blocking wait for buffer */
1176 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1177 if (wait_event_interruptible(port
->wait_read
,
1178 saa7164_enc_next_buf(port
))) {
1179 printk(KERN_ERR
"%s() ERESTARTSYS\n", __func__
);
1180 return -ERESTARTSYS
;
1184 /* Pull the first buffer from the used list */
1185 ubuf
= saa7164_enc_next_buf(port
);
1187 while ((count
> 0) && ubuf
) {
1189 /* set remaining bytes to copy */
1190 rem
= ubuf
->actual_size
- ubuf
->pos
;
1191 cnt
= rem
> count
? count
: rem
;
1193 p
= ubuf
->data
+ ubuf
->pos
;
1196 "%s() count=%d cnt=%d rem=%d buf=%p buf->pos=%d\n",
1197 __func__
, (int)count
, cnt
, rem
, ubuf
, ubuf
->pos
);
1199 if (copy_to_user(buffer
, p
, cnt
)) {
1200 printk(KERN_ERR
"%s() copy_to_user failed\n", __func__
);
1202 printk(KERN_ERR
"%s() EFAULT\n", __func__
);
1213 if (ubuf
->pos
> ubuf
->actual_size
)
1214 printk(KERN_ERR
"read() pos > actual, huh?\n");
1216 if (ubuf
->pos
== ubuf
->actual_size
) {
1218 /* finished with current buffer, take next buffer */
1220 /* Requeue the buffer on the free list */
1223 mutex_lock(&port
->dmaqueue_lock
);
1224 list_move_tail(&ubuf
->list
, &port
->list_buf_free
.list
);
1225 mutex_unlock(&port
->dmaqueue_lock
);
1228 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1229 if (wait_event_interruptible(port
->wait_read
,
1230 saa7164_enc_next_buf(port
))) {
1234 ubuf
= saa7164_enc_next_buf(port
);
1244 static unsigned int fops_poll(struct file
*file
, poll_table
*wait
)
1246 struct saa7164_encoder_fh
*fh
=
1247 (struct saa7164_encoder_fh
*)file
->private_data
;
1248 struct saa7164_port
*port
= fh
->port
;
1249 unsigned int mask
= 0;
1251 port
->last_poll_msecs_diff
= port
->last_poll_msecs
;
1252 port
->last_poll_msecs
= jiffies_to_msecs(jiffies
);
1253 port
->last_poll_msecs_diff
= port
->last_poll_msecs
-
1254 port
->last_poll_msecs_diff
;
1256 saa7164_histogram_update(&port
->poll_interval
,
1257 port
->last_poll_msecs_diff
);
1259 if (!video_is_registered(port
->v4l_device
))
1262 if (atomic_cmpxchg(&fh
->v4l_reading
, 0, 1) == 0) {
1263 if (atomic_inc_return(&port
->v4l_reader_count
) == 1) {
1264 if (saa7164_encoder_initialize(port
) < 0)
1266 saa7164_encoder_start_streaming(port
);
1271 /* blocking wait for buffer */
1272 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1273 if (wait_event_interruptible(port
->wait_read
,
1274 saa7164_enc_next_buf(port
))) {
1275 return -ERESTARTSYS
;
1279 /* Pull the first buffer from the used list */
1280 if (!list_empty(&port
->list_buf_used
.list
))
1281 mask
|= POLLIN
| POLLRDNORM
;
1286 static const struct v4l2_file_operations mpeg_fops
= {
1287 .owner
= THIS_MODULE
,
1289 .release
= fops_release
,
1292 .unlocked_ioctl
= video_ioctl2
,
1295 int saa7164_g_chip_ident(struct file
*file
, void *fh
,
1296 struct v4l2_dbg_chip_ident
*chip
)
1298 struct saa7164_port
*port
= ((struct saa7164_encoder_fh
*)fh
)->port
;
1299 struct saa7164_dev
*dev
= port
->dev
;
1300 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1305 int saa7164_g_register(struct file
*file
, void *fh
,
1306 struct v4l2_dbg_register
*reg
)
1308 struct saa7164_port
*port
= ((struct saa7164_encoder_fh
*)fh
)->port
;
1309 struct saa7164_dev
*dev
= port
->dev
;
1310 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1312 if (!capable(CAP_SYS_ADMIN
))
1318 int saa7164_s_register(struct file
*file
, void *fh
,
1319 struct v4l2_dbg_register
*reg
)
1321 struct saa7164_port
*port
= ((struct saa7164_encoder_fh
*)fh
)->port
;
1322 struct saa7164_dev
*dev
= port
->dev
;
1323 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1325 if (!capable(CAP_SYS_ADMIN
))
1331 static const struct v4l2_ioctl_ops mpeg_ioctl_ops
= {
1332 .vidioc_s_std
= vidioc_s_std
,
1333 .vidioc_enum_input
= vidioc_enum_input
,
1334 .vidioc_g_input
= vidioc_g_input
,
1335 .vidioc_s_input
= vidioc_s_input
,
1336 .vidioc_g_tuner
= vidioc_g_tuner
,
1337 .vidioc_s_tuner
= vidioc_s_tuner
,
1338 .vidioc_g_frequency
= vidioc_g_frequency
,
1339 .vidioc_s_frequency
= vidioc_s_frequency
,
1340 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1341 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1342 .vidioc_querycap
= vidioc_querycap
,
1343 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1344 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1345 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1346 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1347 .vidioc_g_ext_ctrls
= vidioc_g_ext_ctrls
,
1348 .vidioc_s_ext_ctrls
= vidioc_s_ext_ctrls
,
1349 .vidioc_try_ext_ctrls
= vidioc_try_ext_ctrls
,
1350 .vidioc_log_status
= vidioc_log_status
,
1351 .vidioc_queryctrl
= vidioc_queryctrl
,
1352 .vidioc_g_chip_ident
= saa7164_g_chip_ident
,
1353 #ifdef CONFIG_VIDEO_ADV_DEBUG
1354 .vidioc_g_register
= saa7164_g_register
,
1355 .vidioc_s_register
= saa7164_s_register
,
1359 static struct video_device saa7164_mpeg_template
= {
1362 .ioctl_ops
= &mpeg_ioctl_ops
,
1364 .tvnorms
= SAA7164_NORMS
,
1365 .current_norm
= V4L2_STD_NTSC_M
,
1368 static struct video_device
*saa7164_encoder_alloc(
1369 struct saa7164_port
*port
,
1370 struct pci_dev
*pci
,
1371 struct video_device
*template,
1374 struct video_device
*vfd
;
1375 struct saa7164_dev
*dev
= port
->dev
;
1377 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1379 vfd
= video_device_alloc();
1384 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)", dev
->name
,
1385 type
, saa7164_boards
[dev
->board
].name
);
1387 vfd
->parent
= &pci
->dev
;
1388 vfd
->release
= video_device_release
;
1392 int saa7164_encoder_register(struct saa7164_port
*port
)
1394 struct saa7164_dev
*dev
= port
->dev
;
1395 int result
= -ENODEV
;
1397 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1399 if (port
->type
!= SAA7164_MPEG_ENCODER
)
1402 /* Sanity check that the PCI configuration space is active */
1403 if (port
->hwcfg
.BARLocation
== 0) {
1404 printk(KERN_ERR
"%s() failed "
1405 "(errno = %d), NO PCI configuration\n",
1411 /* Establish encoder defaults here */
1412 /* Set default TV standard */
1413 port
->encodernorm
= saa7164_tvnorms
[0];
1415 port
->mux_input
= 1; /* Composite */
1416 port
->video_format
= EU_VIDEO_FORMAT_MPEG_2
;
1417 port
->audio_format
= 0;
1418 port
->video_resolution
= 0;
1419 port
->ctl_brightness
= 127;
1420 port
->ctl_contrast
= 66;
1421 port
->ctl_hue
= 128;
1422 port
->ctl_saturation
= 62;
1423 port
->ctl_sharpness
= 8;
1424 port
->encoder_params
.bitrate
= ENCODER_DEF_BITRATE
;
1425 port
->encoder_params
.bitrate_peak
= ENCODER_DEF_BITRATE
;
1426 port
->encoder_params
.bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
;
1427 port
->encoder_params
.stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_PS
;
1428 port
->encoder_params
.ctl_mute
= 0;
1429 port
->encoder_params
.ctl_aspect
= V4L2_MPEG_VIDEO_ASPECT_4x3
;
1430 port
->encoder_params
.refdist
= 1;
1431 port
->encoder_params
.gop_size
= SAA7164_ENCODER_DEFAULT_GOP_SIZE
;
1433 if (port
->encodernorm
.id
& V4L2_STD_525_60
)
1438 /* Allocate and register the video device node */
1439 port
->v4l_device
= saa7164_encoder_alloc(port
,
1440 dev
->pci
, &saa7164_mpeg_template
, "mpeg");
1442 if (!port
->v4l_device
) {
1443 printk(KERN_INFO
"%s: can't allocate mpeg device\n",
1449 video_set_drvdata(port
->v4l_device
, port
);
1450 result
= video_register_device(port
->v4l_device
,
1451 VFL_TYPE_GRABBER
, -1);
1453 printk(KERN_INFO
"%s: can't register mpeg device\n",
1455 /* TODO: We're going to leak here if we don't dealloc
1456 The buffers above. The unreg function can't deal wit it.
1461 printk(KERN_INFO
"%s: registered device video%d [mpeg]\n",
1462 dev
->name
, port
->v4l_device
->num
);
1464 /* Configure the hardware defaults */
1465 saa7164_api_set_videomux(port
);
1466 saa7164_api_set_usercontrol(port
, PU_BRIGHTNESS_CONTROL
);
1467 saa7164_api_set_usercontrol(port
, PU_CONTRAST_CONTROL
);
1468 saa7164_api_set_usercontrol(port
, PU_HUE_CONTROL
);
1469 saa7164_api_set_usercontrol(port
, PU_SATURATION_CONTROL
);
1470 saa7164_api_set_usercontrol(port
, PU_SHARPNESS_CONTROL
);
1471 saa7164_api_audio_mute(port
, 0);
1472 saa7164_api_set_audio_volume(port
, 20);
1473 saa7164_api_set_aspect_ratio(port
);
1475 /* Disable audio standard detection, it's buggy */
1476 saa7164_api_set_audio_detection(port
, 0);
1478 saa7164_api_set_encoder(port
);
1479 saa7164_api_get_encoder(port
);
1486 void saa7164_encoder_unregister(struct saa7164_port
*port
)
1488 struct saa7164_dev
*dev
= port
->dev
;
1490 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
1492 if (port
->type
!= SAA7164_MPEG_ENCODER
)
1495 if (port
->v4l_device
) {
1496 if (port
->v4l_device
->minor
!= -1)
1497 video_unregister_device(port
->v4l_device
);
1499 video_device_release(port
->v4l_device
);
1501 port
->v4l_device
= NULL
;
1504 dprintk(DBGLVL_ENC
, "%s(port=%d) done\n", __func__
, port
->nr
);