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
];
233 /* Update the audio decoder while is not running in
236 saa7164_api_set_audio_std(port
);
238 dprintk(DBGLVL_ENC
, "%s(id=0x%x) OK\n", __func__
, (u32
)id
);
243 static int vidioc_g_std(struct file
*file
, void *priv
, v4l2_std_id
*id
)
245 struct saa7164_encoder_fh
*fh
= file
->private_data
;
246 struct saa7164_port
*port
= fh
->port
;
252 static int vidioc_enum_input(struct file
*file
, void *priv
,
253 struct v4l2_input
*i
)
257 char *inputs
[] = { "tuner", "composite", "svideo", "aux",
258 "composite 2", "svideo 2", "aux 2" };
263 strcpy(i
->name
, inputs
[i
->index
]);
266 i
->type
= V4L2_INPUT_TYPE_TUNER
;
268 i
->type
= V4L2_INPUT_TYPE_CAMERA
;
270 for (n
= 0; n
< ARRAY_SIZE(saa7164_tvnorms
); n
++)
271 i
->std
|= saa7164_tvnorms
[n
].id
;
276 static int vidioc_g_input(struct file
*file
, void *priv
, unsigned int *i
)
278 struct saa7164_encoder_fh
*fh
= file
->private_data
;
279 struct saa7164_port
*port
= fh
->port
;
280 struct saa7164_dev
*dev
= port
->dev
;
282 if (saa7164_api_get_videomux(port
) != SAA_OK
)
285 *i
= (port
->mux_input
- 1);
287 dprintk(DBGLVL_ENC
, "%s() input=%d\n", __func__
, *i
);
292 static int vidioc_s_input(struct file
*file
, void *priv
, unsigned int i
)
294 struct saa7164_encoder_fh
*fh
= file
->private_data
;
295 struct saa7164_port
*port
= fh
->port
;
296 struct saa7164_dev
*dev
= port
->dev
;
298 dprintk(DBGLVL_ENC
, "%s() input=%d\n", __func__
, i
);
303 port
->mux_input
= i
+ 1;
305 if (saa7164_api_set_videomux(port
) != SAA_OK
)
311 static int vidioc_g_tuner(struct file
*file
, void *priv
,
312 struct v4l2_tuner
*t
)
314 struct saa7164_encoder_fh
*fh
= file
->private_data
;
315 struct saa7164_port
*port
= fh
->port
;
316 struct saa7164_dev
*dev
= port
->dev
;
321 strcpy(t
->name
, "tuner");
322 t
->type
= V4L2_TUNER_ANALOG_TV
;
323 t
->capability
= V4L2_TUNER_CAP_NORM
| V4L2_TUNER_CAP_STEREO
;
325 dprintk(DBGLVL_ENC
, "VIDIOC_G_TUNER: tuner type %d\n", t
->type
);
330 static int vidioc_s_tuner(struct file
*file
, void *priv
,
331 const struct v4l2_tuner
*t
)
333 /* Update the A/V core */
337 static int vidioc_g_frequency(struct file
*file
, void *priv
,
338 struct v4l2_frequency
*f
)
340 struct saa7164_encoder_fh
*fh
= file
->private_data
;
341 struct saa7164_port
*port
= fh
->port
;
343 f
->type
= V4L2_TUNER_ANALOG_TV
;
344 f
->frequency
= port
->freq
;
349 static int vidioc_s_frequency(struct file
*file
, void *priv
,
350 const struct v4l2_frequency
*f
)
352 struct saa7164_encoder_fh
*fh
= file
->private_data
;
353 struct saa7164_port
*port
= fh
->port
;
354 struct saa7164_dev
*dev
= port
->dev
;
355 struct saa7164_port
*tsport
;
356 struct dvb_frontend
*fe
;
358 /* TODO: Pull this for the std */
359 struct analog_parameters params
= {
360 .mode
= V4L2_TUNER_ANALOG_TV
,
361 .audmode
= V4L2_TUNER_MODE_STEREO
,
362 .std
= port
->encodernorm
.id
,
363 .frequency
= f
->frequency
366 /* Stop the encoder */
367 dprintk(DBGLVL_ENC
, "%s() frequency=%d tuner=%d\n", __func__
,
368 f
->frequency
, f
->tuner
);
373 if (f
->type
!= V4L2_TUNER_ANALOG_TV
)
376 port
->freq
= f
->frequency
;
378 /* Update the hardware */
379 if (port
->nr
== SAA7164_PORT_ENC1
)
380 tsport
= &dev
->ports
[SAA7164_PORT_TS1
];
382 if (port
->nr
== SAA7164_PORT_ENC2
)
383 tsport
= &dev
->ports
[SAA7164_PORT_TS2
];
387 fe
= tsport
->dvb
.frontend
;
389 if (fe
&& fe
->ops
.tuner_ops
.set_analog_params
)
390 fe
->ops
.tuner_ops
.set_analog_params(fe
, ¶ms
);
392 printk(KERN_ERR
"%s() No analog tuner, aborting\n", __func__
);
394 saa7164_encoder_initialize(port
);
399 static int vidioc_g_ctrl(struct file
*file
, void *priv
,
400 struct v4l2_control
*ctl
)
402 struct saa7164_encoder_fh
*fh
= file
->private_data
;
403 struct saa7164_port
*port
= fh
->port
;
404 struct saa7164_dev
*dev
= port
->dev
;
406 dprintk(DBGLVL_ENC
, "%s(id=%d, value=%d)\n", __func__
,
407 ctl
->id
, ctl
->value
);
410 case V4L2_CID_BRIGHTNESS
:
411 ctl
->value
= port
->ctl_brightness
;
413 case V4L2_CID_CONTRAST
:
414 ctl
->value
= port
->ctl_contrast
;
416 case V4L2_CID_SATURATION
:
417 ctl
->value
= port
->ctl_saturation
;
420 ctl
->value
= port
->ctl_hue
;
422 case V4L2_CID_SHARPNESS
:
423 ctl
->value
= port
->ctl_sharpness
;
425 case V4L2_CID_AUDIO_VOLUME
:
426 ctl
->value
= port
->ctl_volume
;
435 static int vidioc_s_ctrl(struct file
*file
, void *priv
,
436 struct v4l2_control
*ctl
)
438 struct saa7164_encoder_fh
*fh
= file
->private_data
;
439 struct saa7164_port
*port
= fh
->port
;
440 struct saa7164_dev
*dev
= port
->dev
;
443 dprintk(DBGLVL_ENC
, "%s(id=%d, value=%d)\n", __func__
,
444 ctl
->id
, ctl
->value
);
447 case V4L2_CID_BRIGHTNESS
:
448 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
449 port
->ctl_brightness
= ctl
->value
;
450 saa7164_api_set_usercontrol(port
,
451 PU_BRIGHTNESS_CONTROL
);
455 case V4L2_CID_CONTRAST
:
456 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
457 port
->ctl_contrast
= ctl
->value
;
458 saa7164_api_set_usercontrol(port
, PU_CONTRAST_CONTROL
);
462 case V4L2_CID_SATURATION
:
463 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
464 port
->ctl_saturation
= ctl
->value
;
465 saa7164_api_set_usercontrol(port
,
466 PU_SATURATION_CONTROL
);
471 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
472 port
->ctl_hue
= ctl
->value
;
473 saa7164_api_set_usercontrol(port
, PU_HUE_CONTROL
);
477 case V4L2_CID_SHARPNESS
:
478 if ((ctl
->value
>= 0) && (ctl
->value
<= 255)) {
479 port
->ctl_sharpness
= ctl
->value
;
480 saa7164_api_set_usercontrol(port
, PU_SHARPNESS_CONTROL
);
484 case V4L2_CID_AUDIO_VOLUME
:
485 if ((ctl
->value
>= -83) && (ctl
->value
<= 24)) {
486 port
->ctl_volume
= ctl
->value
;
487 saa7164_api_set_audio_volume(port
, port
->ctl_volume
);
498 static int saa7164_get_ctrl(struct saa7164_port
*port
,
499 struct v4l2_ext_control
*ctrl
)
501 struct saa7164_encoder_params
*params
= &port
->encoder_params
;
504 case V4L2_CID_MPEG_VIDEO_BITRATE
:
505 ctrl
->value
= params
->bitrate
;
507 case V4L2_CID_MPEG_STREAM_TYPE
:
508 ctrl
->value
= params
->stream_type
;
510 case V4L2_CID_MPEG_AUDIO_MUTE
:
511 ctrl
->value
= params
->ctl_mute
;
513 case V4L2_CID_MPEG_VIDEO_ASPECT
:
514 ctrl
->value
= params
->ctl_aspect
;
516 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
517 ctrl
->value
= params
->bitrate_mode
;
519 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
520 ctrl
->value
= params
->refdist
;
522 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
523 ctrl
->value
= params
->bitrate_peak
;
525 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
526 ctrl
->value
= params
->gop_size
;
534 static int vidioc_g_ext_ctrls(struct file
*file
, void *priv
,
535 struct v4l2_ext_controls
*ctrls
)
537 struct saa7164_encoder_fh
*fh
= file
->private_data
;
538 struct saa7164_port
*port
= fh
->port
;
541 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
542 for (i
= 0; i
< ctrls
->count
; i
++) {
543 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
545 err
= saa7164_get_ctrl(port
, ctrl
);
547 ctrls
->error_idx
= i
;
558 static int saa7164_try_ctrl(struct v4l2_ext_control
*ctrl
, int ac3
)
563 case V4L2_CID_MPEG_VIDEO_BITRATE
:
564 if ((ctrl
->value
>= ENCODER_MIN_BITRATE
) &&
565 (ctrl
->value
<= ENCODER_MAX_BITRATE
))
568 case V4L2_CID_MPEG_STREAM_TYPE
:
569 if ((ctrl
->value
== V4L2_MPEG_STREAM_TYPE_MPEG2_PS
) ||
570 (ctrl
->value
== V4L2_MPEG_STREAM_TYPE_MPEG2_TS
))
573 case V4L2_CID_MPEG_AUDIO_MUTE
:
574 if ((ctrl
->value
>= 0) &&
578 case V4L2_CID_MPEG_VIDEO_ASPECT
:
579 if ((ctrl
->value
>= V4L2_MPEG_VIDEO_ASPECT_1x1
) &&
580 (ctrl
->value
<= V4L2_MPEG_VIDEO_ASPECT_221x100
))
583 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
584 if ((ctrl
->value
>= 0) &&
585 (ctrl
->value
<= 255))
588 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
589 if ((ctrl
->value
== V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
) ||
590 (ctrl
->value
== V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
))
593 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
594 if ((ctrl
->value
>= 1) &&
598 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
599 if ((ctrl
->value
>= ENCODER_MIN_BITRATE
) &&
600 (ctrl
->value
<= ENCODER_MAX_BITRATE
))
610 static int vidioc_try_ext_ctrls(struct file
*file
, void *priv
,
611 struct v4l2_ext_controls
*ctrls
)
615 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
616 for (i
= 0; i
< ctrls
->count
; i
++) {
617 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
619 err
= saa7164_try_ctrl(ctrl
, 0);
621 ctrls
->error_idx
= i
;
631 static int saa7164_set_ctrl(struct saa7164_port
*port
,
632 struct v4l2_ext_control
*ctrl
)
634 struct saa7164_encoder_params
*params
= &port
->encoder_params
;
638 case V4L2_CID_MPEG_VIDEO_BITRATE
:
639 params
->bitrate
= ctrl
->value
;
641 case V4L2_CID_MPEG_STREAM_TYPE
:
642 params
->stream_type
= ctrl
->value
;
644 case V4L2_CID_MPEG_AUDIO_MUTE
:
645 params
->ctl_mute
= ctrl
->value
;
646 ret
= saa7164_api_audio_mute(port
, params
->ctl_mute
);
648 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
653 case V4L2_CID_MPEG_VIDEO_ASPECT
:
654 params
->ctl_aspect
= ctrl
->value
;
655 ret
= saa7164_api_set_aspect_ratio(port
);
657 printk(KERN_ERR
"%s() error, ret = 0x%x\n", __func__
,
662 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
663 params
->bitrate_mode
= ctrl
->value
;
665 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
666 params
->refdist
= ctrl
->value
;
668 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
669 params
->bitrate_peak
= ctrl
->value
;
671 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
672 params
->gop_size
= ctrl
->value
;
678 /* TODO: Update the hardware */
683 static int vidioc_s_ext_ctrls(struct file
*file
, void *priv
,
684 struct v4l2_ext_controls
*ctrls
)
686 struct saa7164_encoder_fh
*fh
= file
->private_data
;
687 struct saa7164_port
*port
= fh
->port
;
690 if (ctrls
->ctrl_class
== V4L2_CTRL_CLASS_MPEG
) {
691 for (i
= 0; i
< ctrls
->count
; i
++) {
692 struct v4l2_ext_control
*ctrl
= ctrls
->controls
+ i
;
694 err
= saa7164_try_ctrl(ctrl
, 0);
696 ctrls
->error_idx
= i
;
699 err
= saa7164_set_ctrl(port
, ctrl
);
701 ctrls
->error_idx
= i
;
712 static int vidioc_querycap(struct file
*file
, void *priv
,
713 struct v4l2_capability
*cap
)
715 struct saa7164_encoder_fh
*fh
= file
->private_data
;
716 struct saa7164_port
*port
= fh
->port
;
717 struct saa7164_dev
*dev
= port
->dev
;
719 strcpy(cap
->driver
, dev
->name
);
720 strlcpy(cap
->card
, saa7164_boards
[dev
->board
].name
,
722 sprintf(cap
->bus_info
, "PCI:%s", pci_name(dev
->pci
));
725 V4L2_CAP_VIDEO_CAPTURE
|
729 cap
->capabilities
|= V4L2_CAP_TUNER
;
735 static int vidioc_enum_fmt_vid_cap(struct file
*file
, void *priv
,
736 struct v4l2_fmtdesc
*f
)
741 strlcpy(f
->description
, "MPEG", sizeof(f
->description
));
742 f
->pixelformat
= V4L2_PIX_FMT_MPEG
;
747 static int vidioc_g_fmt_vid_cap(struct file
*file
, void *priv
,
748 struct v4l2_format
*f
)
750 struct saa7164_encoder_fh
*fh
= file
->private_data
;
751 struct saa7164_port
*port
= fh
->port
;
752 struct saa7164_dev
*dev
= port
->dev
;
754 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
755 f
->fmt
.pix
.bytesperline
= 0;
756 f
->fmt
.pix
.sizeimage
=
757 port
->ts_packet_size
* port
->ts_packet_count
;
758 f
->fmt
.pix
.colorspace
= 0;
759 f
->fmt
.pix
.width
= port
->width
;
760 f
->fmt
.pix
.height
= port
->height
;
762 dprintk(DBGLVL_ENC
, "VIDIOC_G_FMT: w: %d, h: %d\n",
763 port
->width
, port
->height
);
768 static int vidioc_try_fmt_vid_cap(struct file
*file
, void *priv
,
769 struct v4l2_format
*f
)
771 struct saa7164_encoder_fh
*fh
= file
->private_data
;
772 struct saa7164_port
*port
= fh
->port
;
773 struct saa7164_dev
*dev
= port
->dev
;
775 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
776 f
->fmt
.pix
.bytesperline
= 0;
777 f
->fmt
.pix
.sizeimage
=
778 port
->ts_packet_size
* port
->ts_packet_count
;
779 f
->fmt
.pix
.colorspace
= 0;
780 dprintk(DBGLVL_ENC
, "VIDIOC_TRY_FMT: w: %d, h: %d\n",
781 port
->width
, port
->height
);
785 static int vidioc_s_fmt_vid_cap(struct file
*file
, void *priv
,
786 struct v4l2_format
*f
)
788 struct saa7164_encoder_fh
*fh
= file
->private_data
;
789 struct saa7164_port
*port
= fh
->port
;
790 struct saa7164_dev
*dev
= port
->dev
;
792 f
->fmt
.pix
.pixelformat
= V4L2_PIX_FMT_MPEG
;
793 f
->fmt
.pix
.bytesperline
= 0;
794 f
->fmt
.pix
.sizeimage
=
795 port
->ts_packet_size
* port
->ts_packet_count
;
796 f
->fmt
.pix
.colorspace
= 0;
798 dprintk(DBGLVL_ENC
, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
799 f
->fmt
.pix
.width
, f
->fmt
.pix
.height
, f
->fmt
.pix
.field
);
804 static int fill_queryctrl(struct saa7164_encoder_params
*params
,
805 struct v4l2_queryctrl
*c
)
808 case V4L2_CID_BRIGHTNESS
:
809 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 127);
810 case V4L2_CID_CONTRAST
:
811 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 66);
812 case V4L2_CID_SATURATION
:
813 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 62);
815 return v4l2_ctrl_query_fill(c
, 0x0, 0xff, 1, 128);
816 case V4L2_CID_SHARPNESS
:
817 return v4l2_ctrl_query_fill(c
, 0x0, 0x0f, 1, 8);
818 case V4L2_CID_MPEG_AUDIO_MUTE
:
819 return v4l2_ctrl_query_fill(c
, 0x0, 0x01, 1, 0);
820 case V4L2_CID_AUDIO_VOLUME
:
821 return v4l2_ctrl_query_fill(c
, -83, 24, 1, 20);
822 case V4L2_CID_MPEG_VIDEO_BITRATE
:
823 return v4l2_ctrl_query_fill(c
,
824 ENCODER_MIN_BITRATE
, ENCODER_MAX_BITRATE
,
825 100000, ENCODER_DEF_BITRATE
);
826 case V4L2_CID_MPEG_STREAM_TYPE
:
827 return v4l2_ctrl_query_fill(c
,
828 V4L2_MPEG_STREAM_TYPE_MPEG2_PS
,
829 V4L2_MPEG_STREAM_TYPE_MPEG2_TS
,
830 1, V4L2_MPEG_STREAM_TYPE_MPEG2_PS
);
831 case V4L2_CID_MPEG_VIDEO_ASPECT
:
832 return v4l2_ctrl_query_fill(c
,
833 V4L2_MPEG_VIDEO_ASPECT_1x1
,
834 V4L2_MPEG_VIDEO_ASPECT_221x100
,
835 1, V4L2_MPEG_VIDEO_ASPECT_4x3
);
836 case V4L2_CID_MPEG_VIDEO_GOP_SIZE
:
837 return v4l2_ctrl_query_fill(c
, 1, 255, 1, 15);
838 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE
:
839 return v4l2_ctrl_query_fill(c
,
840 V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
,
841 V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
,
842 1, V4L2_MPEG_VIDEO_BITRATE_MODE_VBR
);
843 case V4L2_CID_MPEG_VIDEO_B_FRAMES
:
844 return v4l2_ctrl_query_fill(c
,
846 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK
:
847 return v4l2_ctrl_query_fill(c
,
848 ENCODER_MIN_BITRATE
, ENCODER_MAX_BITRATE
,
849 100000, ENCODER_DEF_BITRATE
);
855 static int vidioc_queryctrl(struct file
*file
, void *priv
,
856 struct v4l2_queryctrl
*c
)
858 struct saa7164_encoder_fh
*fh
= priv
;
859 struct saa7164_port
*port
= fh
->port
;
863 memset(c
, 0, sizeof(*c
));
865 next
= !!(id
& V4L2_CTRL_FLAG_NEXT_CTRL
);
866 c
->id
= id
& ~V4L2_CTRL_FLAG_NEXT_CTRL
;
868 for (i
= 0; i
< ARRAY_SIZE(saa7164_v4l2_ctrls
); i
++) {
870 if (c
->id
< saa7164_v4l2_ctrls
[i
])
871 c
->id
= saa7164_v4l2_ctrls
[i
];
876 if (c
->id
== saa7164_v4l2_ctrls
[i
])
877 return fill_queryctrl(&port
->encoder_params
, c
);
879 if (c
->id
< saa7164_v4l2_ctrls
[i
])
886 static int saa7164_encoder_stop_port(struct saa7164_port
*port
)
888 struct saa7164_dev
*dev
= port
->dev
;
891 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
892 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
893 printk(KERN_ERR
"%s() stop transition failed, ret = 0x%x\n",
897 dprintk(DBGLVL_ENC
, "%s() Stopped\n", __func__
);
904 static int saa7164_encoder_acquire_port(struct saa7164_port
*port
)
906 struct saa7164_dev
*dev
= port
->dev
;
909 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_ACQUIRE
);
910 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
911 printk(KERN_ERR
"%s() acquire transition failed, ret = 0x%x\n",
915 dprintk(DBGLVL_ENC
, "%s() Acquired\n", __func__
);
922 static int saa7164_encoder_pause_port(struct saa7164_port
*port
)
924 struct saa7164_dev
*dev
= port
->dev
;
927 ret
= saa7164_api_transition_port(port
, SAA_DMASTATE_PAUSE
);
928 if ((ret
!= SAA_OK
) && (ret
!= SAA_ERR_ALREADY_STOPPED
)) {
929 printk(KERN_ERR
"%s() pause transition failed, ret = 0x%x\n",
933 dprintk(DBGLVL_ENC
, "%s() Paused\n", __func__
);
940 /* Firmware is very windows centric, meaning you have to transition
941 * the part through AVStream / KS Windows stages, forwards or backwards.
942 * States are: stopped, acquired (h/w), paused, started.
943 * We have to leave here will all of the soft buffers on the free list,
944 * else the cfg_post() func won't have soft buffers to correctly configure.
946 static int saa7164_encoder_stop_streaming(struct saa7164_port
*port
)
948 struct saa7164_dev
*dev
= port
->dev
;
949 struct saa7164_buffer
*buf
;
950 struct saa7164_user_buffer
*ubuf
;
951 struct list_head
*c
, *n
;
954 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
956 ret
= saa7164_encoder_pause_port(port
);
957 ret
= saa7164_encoder_acquire_port(port
);
958 ret
= saa7164_encoder_stop_port(port
);
960 dprintk(DBGLVL_ENC
, "%s(port=%d) Hardware stopped\n", __func__
,
963 /* Reset the state of any allocated buffer resources */
964 mutex_lock(&port
->dmaqueue_lock
);
966 /* Reset the hard and soft buffer state */
967 list_for_each_safe(c
, n
, &port
->dmaqueue
.list
) {
968 buf
= list_entry(c
, struct saa7164_buffer
, list
);
969 buf
->flags
= SAA7164_BUFFER_FREE
;
973 list_for_each_safe(c
, n
, &port
->list_buf_used
.list
) {
974 ubuf
= list_entry(c
, struct saa7164_user_buffer
, list
);
976 list_move_tail(&ubuf
->list
, &port
->list_buf_free
.list
);
979 mutex_unlock(&port
->dmaqueue_lock
);
981 /* Free any allocated resources */
982 saa7164_encoder_buffers_dealloc(port
);
984 dprintk(DBGLVL_ENC
, "%s(port=%d) Released\n", __func__
, port
->nr
);
989 static int saa7164_encoder_start_streaming(struct saa7164_port
*port
)
991 struct saa7164_dev
*dev
= port
->dev
;
994 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
996 port
->done_first_interrupt
= 0;
998 /* allocate all of the PCIe DMA buffer resources on the fly,
999 * allowing switching between TS and PS payloads without
1000 * requiring a complete driver reload.
1002 saa7164_encoder_buffers_alloc(port
);
1004 /* Configure the encoder with any cache values */
1005 saa7164_api_set_encoder(port
);
1006 saa7164_api_get_encoder(port
);
1008 /* Place the empty buffers on the hardware */
1009 saa7164_buffer_cfg_port(port
);
1011 /* Acquire the hardware */
1012 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_ACQUIRE
);
1013 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1014 printk(KERN_ERR
"%s() acquire transition failed, res = 0x%x\n",
1017 /* Stop the hardware, regardless */
1018 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1019 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1020 printk(KERN_ERR
"%s() acquire/forced stop transition "
1021 "failed, res = 0x%x\n", __func__
, result
);
1026 dprintk(DBGLVL_ENC
, "%s() Acquired\n", __func__
);
1028 /* Pause the hardware */
1029 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_PAUSE
);
1030 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1031 printk(KERN_ERR
"%s() pause transition failed, res = 0x%x\n",
1034 /* Stop the hardware, regardless */
1035 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1036 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1037 printk(KERN_ERR
"%s() pause/forced stop transition "
1038 "failed, res = 0x%x\n", __func__
, result
);
1044 dprintk(DBGLVL_ENC
, "%s() Paused\n", __func__
);
1046 /* Start the hardware */
1047 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_RUN
);
1048 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1049 printk(KERN_ERR
"%s() run transition failed, result = 0x%x\n",
1052 /* Stop the hardware, regardless */
1053 result
= saa7164_api_transition_port(port
, SAA_DMASTATE_STOP
);
1054 if ((result
!= SAA_OK
) && (result
!= SAA_ERR_ALREADY_STOPPED
)) {
1055 printk(KERN_ERR
"%s() run/forced stop transition "
1056 "failed, res = 0x%x\n", __func__
, result
);
1061 dprintk(DBGLVL_ENC
, "%s() Running\n", __func__
);
1067 static int fops_open(struct file
*file
)
1069 struct saa7164_dev
*dev
;
1070 struct saa7164_port
*port
;
1071 struct saa7164_encoder_fh
*fh
;
1073 port
= (struct saa7164_port
*)video_get_drvdata(video_devdata(file
));
1079 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1081 /* allocate + initialize per filehandle data */
1082 fh
= kzalloc(sizeof(*fh
), GFP_KERNEL
);
1086 file
->private_data
= fh
;
1092 static int fops_release(struct file
*file
)
1094 struct saa7164_encoder_fh
*fh
= file
->private_data
;
1095 struct saa7164_port
*port
= fh
->port
;
1096 struct saa7164_dev
*dev
= port
->dev
;
1098 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1100 /* Shut device down on last close */
1101 if (atomic_cmpxchg(&fh
->v4l_reading
, 1, 0) == 1) {
1102 if (atomic_dec_return(&port
->v4l_reader_count
) == 0) {
1103 /* stop mpeg capture then cancel buffers */
1104 saa7164_encoder_stop_streaming(port
);
1108 file
->private_data
= NULL
;
1115 saa7164_user_buffer
*saa7164_enc_next_buf(struct saa7164_port
*port
)
1117 struct saa7164_user_buffer
*ubuf
= NULL
;
1118 struct saa7164_dev
*dev
= port
->dev
;
1121 mutex_lock(&port
->dmaqueue_lock
);
1122 if (!list_empty(&port
->list_buf_used
.list
)) {
1123 ubuf
= list_first_entry(&port
->list_buf_used
.list
,
1124 struct saa7164_user_buffer
, list
);
1127 crc
= crc32(0, ubuf
->data
, ubuf
->actual_size
);
1128 if (crc
!= ubuf
->crc
) {
1130 "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n",
1132 ubuf
, ubuf
->crc
, crc
);
1137 mutex_unlock(&port
->dmaqueue_lock
);
1139 dprintk(DBGLVL_ENC
, "%s() returns %p\n", __func__
, ubuf
);
1144 static ssize_t
fops_read(struct file
*file
, char __user
*buffer
,
1145 size_t count
, loff_t
*pos
)
1147 struct saa7164_encoder_fh
*fh
= file
->private_data
;
1148 struct saa7164_port
*port
= fh
->port
;
1149 struct saa7164_user_buffer
*ubuf
= NULL
;
1150 struct saa7164_dev
*dev
= port
->dev
;
1155 port
->last_read_msecs_diff
= port
->last_read_msecs
;
1156 port
->last_read_msecs
= jiffies_to_msecs(jiffies
);
1157 port
->last_read_msecs_diff
= port
->last_read_msecs
-
1158 port
->last_read_msecs_diff
;
1160 saa7164_histogram_update(&port
->read_interval
,
1161 port
->last_read_msecs_diff
);
1164 printk(KERN_ERR
"%s() ESPIPE\n", __func__
);
1168 if (atomic_cmpxchg(&fh
->v4l_reading
, 0, 1) == 0) {
1169 if (atomic_inc_return(&port
->v4l_reader_count
) == 1) {
1171 if (saa7164_encoder_initialize(port
) < 0) {
1172 printk(KERN_ERR
"%s() EINVAL\n", __func__
);
1176 saa7164_encoder_start_streaming(port
);
1181 /* blocking wait for buffer */
1182 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1183 if (wait_event_interruptible(port
->wait_read
,
1184 saa7164_enc_next_buf(port
))) {
1185 printk(KERN_ERR
"%s() ERESTARTSYS\n", __func__
);
1186 return -ERESTARTSYS
;
1190 /* Pull the first buffer from the used list */
1191 ubuf
= saa7164_enc_next_buf(port
);
1193 while ((count
> 0) && ubuf
) {
1195 /* set remaining bytes to copy */
1196 rem
= ubuf
->actual_size
- ubuf
->pos
;
1197 cnt
= rem
> count
? count
: rem
;
1199 p
= ubuf
->data
+ ubuf
->pos
;
1202 "%s() count=%d cnt=%d rem=%d buf=%p buf->pos=%d\n",
1203 __func__
, (int)count
, cnt
, rem
, ubuf
, ubuf
->pos
);
1205 if (copy_to_user(buffer
, p
, cnt
)) {
1206 printk(KERN_ERR
"%s() copy_to_user failed\n", __func__
);
1208 printk(KERN_ERR
"%s() EFAULT\n", __func__
);
1219 if (ubuf
->pos
> ubuf
->actual_size
)
1220 printk(KERN_ERR
"read() pos > actual, huh?\n");
1222 if (ubuf
->pos
== ubuf
->actual_size
) {
1224 /* finished with current buffer, take next buffer */
1226 /* Requeue the buffer on the free list */
1229 mutex_lock(&port
->dmaqueue_lock
);
1230 list_move_tail(&ubuf
->list
, &port
->list_buf_free
.list
);
1231 mutex_unlock(&port
->dmaqueue_lock
);
1234 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1235 if (wait_event_interruptible(port
->wait_read
,
1236 saa7164_enc_next_buf(port
))) {
1240 ubuf
= saa7164_enc_next_buf(port
);
1250 static unsigned int fops_poll(struct file
*file
, poll_table
*wait
)
1252 struct saa7164_encoder_fh
*fh
=
1253 (struct saa7164_encoder_fh
*)file
->private_data
;
1254 struct saa7164_port
*port
= fh
->port
;
1255 unsigned int mask
= 0;
1257 port
->last_poll_msecs_diff
= port
->last_poll_msecs
;
1258 port
->last_poll_msecs
= jiffies_to_msecs(jiffies
);
1259 port
->last_poll_msecs_diff
= port
->last_poll_msecs
-
1260 port
->last_poll_msecs_diff
;
1262 saa7164_histogram_update(&port
->poll_interval
,
1263 port
->last_poll_msecs_diff
);
1265 if (!video_is_registered(port
->v4l_device
))
1268 if (atomic_cmpxchg(&fh
->v4l_reading
, 0, 1) == 0) {
1269 if (atomic_inc_return(&port
->v4l_reader_count
) == 1) {
1270 if (saa7164_encoder_initialize(port
) < 0)
1272 saa7164_encoder_start_streaming(port
);
1277 /* blocking wait for buffer */
1278 if ((file
->f_flags
& O_NONBLOCK
) == 0) {
1279 if (wait_event_interruptible(port
->wait_read
,
1280 saa7164_enc_next_buf(port
))) {
1281 return -ERESTARTSYS
;
1285 /* Pull the first buffer from the used list */
1286 if (!list_empty(&port
->list_buf_used
.list
))
1287 mask
|= POLLIN
| POLLRDNORM
;
1292 static const struct v4l2_file_operations mpeg_fops
= {
1293 .owner
= THIS_MODULE
,
1295 .release
= fops_release
,
1298 .unlocked_ioctl
= video_ioctl2
,
1301 static const struct v4l2_ioctl_ops mpeg_ioctl_ops
= {
1302 .vidioc_s_std
= vidioc_s_std
,
1303 .vidioc_g_std
= vidioc_g_std
,
1304 .vidioc_enum_input
= vidioc_enum_input
,
1305 .vidioc_g_input
= vidioc_g_input
,
1306 .vidioc_s_input
= vidioc_s_input
,
1307 .vidioc_g_tuner
= vidioc_g_tuner
,
1308 .vidioc_s_tuner
= vidioc_s_tuner
,
1309 .vidioc_g_frequency
= vidioc_g_frequency
,
1310 .vidioc_s_frequency
= vidioc_s_frequency
,
1311 .vidioc_s_ctrl
= vidioc_s_ctrl
,
1312 .vidioc_g_ctrl
= vidioc_g_ctrl
,
1313 .vidioc_querycap
= vidioc_querycap
,
1314 .vidioc_enum_fmt_vid_cap
= vidioc_enum_fmt_vid_cap
,
1315 .vidioc_g_fmt_vid_cap
= vidioc_g_fmt_vid_cap
,
1316 .vidioc_try_fmt_vid_cap
= vidioc_try_fmt_vid_cap
,
1317 .vidioc_s_fmt_vid_cap
= vidioc_s_fmt_vid_cap
,
1318 .vidioc_g_ext_ctrls
= vidioc_g_ext_ctrls
,
1319 .vidioc_s_ext_ctrls
= vidioc_s_ext_ctrls
,
1320 .vidioc_try_ext_ctrls
= vidioc_try_ext_ctrls
,
1321 .vidioc_queryctrl
= vidioc_queryctrl
,
1324 static struct video_device saa7164_mpeg_template
= {
1327 .ioctl_ops
= &mpeg_ioctl_ops
,
1329 .tvnorms
= SAA7164_NORMS
,
1332 static struct video_device
*saa7164_encoder_alloc(
1333 struct saa7164_port
*port
,
1334 struct pci_dev
*pci
,
1335 struct video_device
*template,
1338 struct video_device
*vfd
;
1339 struct saa7164_dev
*dev
= port
->dev
;
1341 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1343 vfd
= video_device_alloc();
1348 snprintf(vfd
->name
, sizeof(vfd
->name
), "%s %s (%s)", dev
->name
,
1349 type
, saa7164_boards
[dev
->board
].name
);
1351 vfd
->v4l2_dev
= &dev
->v4l2_dev
;
1352 vfd
->release
= video_device_release
;
1356 int saa7164_encoder_register(struct saa7164_port
*port
)
1358 struct saa7164_dev
*dev
= port
->dev
;
1359 int result
= -ENODEV
;
1361 dprintk(DBGLVL_ENC
, "%s()\n", __func__
);
1363 if (port
->type
!= SAA7164_MPEG_ENCODER
)
1366 /* Sanity check that the PCI configuration space is active */
1367 if (port
->hwcfg
.BARLocation
== 0) {
1368 printk(KERN_ERR
"%s() failed "
1369 "(errno = %d), NO PCI configuration\n",
1375 /* Establish encoder defaults here */
1376 /* Set default TV standard */
1377 port
->encodernorm
= saa7164_tvnorms
[0];
1379 port
->mux_input
= 1; /* Composite */
1380 port
->video_format
= EU_VIDEO_FORMAT_MPEG_2
;
1381 port
->audio_format
= 0;
1382 port
->video_resolution
= 0;
1383 port
->ctl_brightness
= 127;
1384 port
->ctl_contrast
= 66;
1385 port
->ctl_hue
= 128;
1386 port
->ctl_saturation
= 62;
1387 port
->ctl_sharpness
= 8;
1388 port
->encoder_params
.bitrate
= ENCODER_DEF_BITRATE
;
1389 port
->encoder_params
.bitrate_peak
= ENCODER_DEF_BITRATE
;
1390 port
->encoder_params
.bitrate_mode
= V4L2_MPEG_VIDEO_BITRATE_MODE_CBR
;
1391 port
->encoder_params
.stream_type
= V4L2_MPEG_STREAM_TYPE_MPEG2_PS
;
1392 port
->encoder_params
.ctl_mute
= 0;
1393 port
->encoder_params
.ctl_aspect
= V4L2_MPEG_VIDEO_ASPECT_4x3
;
1394 port
->encoder_params
.refdist
= 1;
1395 port
->encoder_params
.gop_size
= SAA7164_ENCODER_DEFAULT_GOP_SIZE
;
1396 port
->std
= V4L2_STD_NTSC_M
;
1398 if (port
->encodernorm
.id
& V4L2_STD_525_60
)
1403 /* Allocate and register the video device node */
1404 port
->v4l_device
= saa7164_encoder_alloc(port
,
1405 dev
->pci
, &saa7164_mpeg_template
, "mpeg");
1407 if (!port
->v4l_device
) {
1408 printk(KERN_INFO
"%s: can't allocate mpeg device\n",
1414 video_set_drvdata(port
->v4l_device
, port
);
1415 result
= video_register_device(port
->v4l_device
,
1416 VFL_TYPE_GRABBER
, -1);
1418 printk(KERN_INFO
"%s: can't register mpeg device\n",
1420 /* TODO: We're going to leak here if we don't dealloc
1421 The buffers above. The unreg function can't deal wit it.
1426 printk(KERN_INFO
"%s: registered device video%d [mpeg]\n",
1427 dev
->name
, port
->v4l_device
->num
);
1429 /* Configure the hardware defaults */
1430 saa7164_api_set_videomux(port
);
1431 saa7164_api_set_usercontrol(port
, PU_BRIGHTNESS_CONTROL
);
1432 saa7164_api_set_usercontrol(port
, PU_CONTRAST_CONTROL
);
1433 saa7164_api_set_usercontrol(port
, PU_HUE_CONTROL
);
1434 saa7164_api_set_usercontrol(port
, PU_SATURATION_CONTROL
);
1435 saa7164_api_set_usercontrol(port
, PU_SHARPNESS_CONTROL
);
1436 saa7164_api_audio_mute(port
, 0);
1437 saa7164_api_set_audio_volume(port
, 20);
1438 saa7164_api_set_aspect_ratio(port
);
1440 /* Disable audio standard detection, it's buggy */
1441 saa7164_api_set_audio_detection(port
, 0);
1443 saa7164_api_set_encoder(port
);
1444 saa7164_api_get_encoder(port
);
1451 void saa7164_encoder_unregister(struct saa7164_port
*port
)
1453 struct saa7164_dev
*dev
= port
->dev
;
1455 dprintk(DBGLVL_ENC
, "%s(port=%d)\n", __func__
, port
->nr
);
1457 if (port
->type
!= SAA7164_MPEG_ENCODER
)
1460 if (port
->v4l_device
) {
1461 if (port
->v4l_device
->minor
!= -1)
1462 video_unregister_device(port
->v4l_device
);
1464 video_device_release(port
->v4l_device
);
1466 port
->v4l_device
= NULL
;
1469 dprintk(DBGLVL_ENC
, "%s(port=%d) done\n", __func__
, port
->nr
);