24 #define ENCODER_MAX_BITRATE 6500000
25 #define ENCODER_MIN_BITRATE 1000000
26 #define ENCODER_DEF_BITRATE 5000000
38 static const u32 saa7164_v4l2_ctrls[] = {
131 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_PS\n",
142 "%s() type=V4L2_MPEG_STREAM_TYPE_MPEG2_TS\n",
160 for (i = 0; i < port->
hwcfg.buffercount; i++) {
167 "(errno = %d), unable to allocate buffer\n",
207 static int saa7164_encoder_initialize(
struct saa7164_port *port)
209 saa7164_encoder_configure(port);
223 for (i = 0; i <
ARRAY_SIZE(saa7164_tvnorms); i++) {
224 if (*
id & saa7164_tvnorms[i].
id)
242 static int vidioc_enum_input(
struct file *file,
void *priv,
247 char *inputs[] = {
"tuner",
"composite",
"svideo",
"aux",
248 "composite 2",
"svideo 2",
"aux 2" };
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)
282 static int vidioc_s_input(
struct file *file,
void *priv,
unsigned int i)
301 static int vidioc_g_tuner(
struct file *file,
void *priv,
320 static int vidioc_s_tuner(
struct file *file,
void *priv,
327 static int vidioc_g_frequency(
struct file *file,
void *priv,
339 static int vidioc_s_frequency(
struct file *file,
void *priv,
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);
384 saa7164_encoder_initialize(port);
389 static int vidioc_g_ctrl(
struct file *file,
void *priv,
425 static int vidioc_s_ctrl(
struct file *file,
void *priv,
438 if ((ctl->
value >= 0) && (ctl->
value <= 255)) {
446 if ((ctl->
value >= 0) && (ctl->
value <= 255)) {
453 if ((ctl->
value >= 0) && (ctl->
value <= 255)) {
461 if ((ctl->
value >= 0) && (ctl->
value <= 255)) {
468 if ((ctl->
value >= 0) && (ctl->
value <= 255)) {
475 if ((ctl->
value >= -83) && (ctl->
value <= 24)) {
524 static int vidioc_g_ext_ctrls(
struct file *file,
void *priv,
532 for (i = 0; i < ctrls->
count; i++) {
535 err = saa7164_get_ctrl(port, ctrl);
564 if ((ctrl->
value >= 0) &&
574 if ((ctrl->
value >= 0) &&
575 (ctrl->
value <= 255))
584 if ((ctrl->
value >= 1) &&
600 static int vidioc_try_ext_ctrls(
struct file *file,
void *priv,
606 for (i = 0; i < ctrls->
count; i++) {
609 err = saa7164_try_ctrl(ctrl, 0);
673 static int vidioc_s_ext_ctrls(
struct file *file,
void *priv,
681 for (i = 0; i < ctrls->
count; i++) {
684 err = saa7164_try_ctrl(ctrl, 0);
689 err = saa7164_set_ctrl(port, ctrl);
702 static int vidioc_querycap(
struct file *file,
void *priv,
725 static int vidioc_enum_fmt_vid_cap(
struct file *file,
void *priv,
737 static int vidioc_g_fmt_vid_cap(
struct file *file,
void *priv,
745 f->
fmt.
pix.bytesperline = 0;
748 f->
fmt.
pix.colorspace = 0;
758 static int vidioc_try_fmt_vid_cap(
struct file *file,
void *priv,
766 f->
fmt.
pix.bytesperline = 0;
769 f->
fmt.
pix.colorspace = 0;
775 static int vidioc_s_fmt_vid_cap(
struct file *file,
void *priv,
783 f->
fmt.
pix.bytesperline = 0;
786 f->
fmt.
pix.colorspace = 0;
845 static int vidioc_queryctrl(
struct file *file,
void *priv,
858 for (i = 0; i <
ARRAY_SIZE(saa7164_v4l2_ctrls); i++) {
860 if (c->
id < saa7164_v4l2_ctrls[i])
861 c->
id = saa7164_v4l2_ctrls[
i];
866 if (c->
id == saa7164_v4l2_ctrls[i])
869 if (c->
id < saa7164_v4l2_ctrls[i])
876 static int saa7164_encoder_stop_port(
struct saa7164_port *port)
894 static int saa7164_encoder_acquire_port(
struct saa7164_port *port)
912 static int saa7164_encoder_pause_port(
struct saa7164_port *port)
936 static int saa7164_encoder_stop_streaming(
struct saa7164_port *port)
946 ret = saa7164_encoder_pause_port(port);
947 ret = saa7164_encoder_acquire_port(port);
948 ret = saa7164_encoder_stop_port(port);
972 saa7164_encoder_buffers_dealloc(port);
979 static int saa7164_encoder_start_streaming(
struct saa7164_port *port)
992 saa7164_encoder_buffers_alloc(port);
1011 "failed, res = 0x%x\n", __func__, result);
1028 "failed, res = 0x%x\n", __func__, result);
1046 "failed, res = 0x%x\n", __func__, result);
1057 static int fops_open(
struct file *file)
1082 static int fops_release(
struct file *file)
1094 saa7164_encoder_stop_streaming(port);
1117 if (crc != ubuf->
crc) {
1119 "%s() ubuf %p crc became invalid, was 0x%x became 0x%x\n",
1121 ubuf, ubuf->
crc, crc);
1133 static ssize_t fops_read(
struct file *file,
char __user *
buffer,
1160 if (saa7164_encoder_initialize(port) < 0) {
1165 saa7164_encoder_start_streaming(port);
1182 while ((count > 0) && ubuf) {
1186 cnt = rem > count ? count : rem;
1191 "%s() count=%d cnt=%d rem=%d buf=%p buf->pos=%d\n",
1192 __func__, (
int)count, cnt, rem, ubuf, ubuf->
pos);
1239 static unsigned int fops_poll(
struct file *file,
poll_table *
wait)
1244 unsigned int mask = 0;
1259 if (saa7164_encoder_initialize(port) < 0)
1261 saa7164_encoder_start_streaming(port);
1284 .release = fops_release,
1347 #ifdef CONFIG_VIDEO_ADV_DEBUG
1356 .ioctl_ops = &mpeg_ioctl_ops,
1397 if (port->
hwcfg.BARLocation == 0) {
1399 "(errno = %d), NO PCI configuration\n",
1433 port->
v4l_device = saa7164_encoder_alloc(port,
1434 dev->
pci, &saa7164_mpeg_template,
"mpeg");
1444 result = video_register_device(port->
v4l_device,