Commit 9aeb4b05 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab Committed by Mauro Carvalho Chehab

V4L/DVB (3423): CodingStyle fixes.

- CodingStyle fixes.
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@infradead.org>
parent 2d50f847
...@@ -1012,19 +1012,15 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form ...@@ -1012,19 +1012,15 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form
width /= 2; width /= 2;
} }
if ((hscale = if ((hscale = (((unsigned long)maxw) << 12) / width - 4096L) >= 0x4000)
(((unsigned long)maxw) << 12) / width - 4096L) >=
0x4000)
hscale = 0x3fff; hscale = 0x3fff;
width =
(((unsigned long)maxw) << 12) / (hscale + 4096L);
if ((vscale = width = (((unsigned long)maxw) << 12) / (hscale + 4096L);
(((unsigned long)maxh) << 12) / height - 4096L) >=
0x4000) if ((vscale = (((unsigned long)maxh) << 12) / height - 4096L) >= 0x4000)
vscale = 0x3fff; vscale = 0x3fff;
height =
(((unsigned long)maxh) << 12) / (vscale + 4096L); height = (((unsigned long)maxh) << 12) / (vscale + 4096L);
format->fmt.pix.width = width; format->fmt.pix.width = width;
format->fmt.pix.height = height; format->fmt.pix.height = height;
...@@ -1035,10 +1031,9 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form ...@@ -1035,10 +1031,9 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form
format->fmt.pix.field = V4L2_FIELD_INTERLACED; format->fmt.pix.field = V4L2_FIELD_INTERLACED;
em28xx_videodbg("%s: returned %dx%d (%d, %d)\n", em28xx_videodbg("%s: returned %dx%d (%d, %d)\n",
cmd == cmd == VIDIOC_TRY_FMT ?
VIDIOC_TRY_FMT ? "VIDIOC_TRY_FMT" : "VIDIOC_TRY_FMT" :"VIDIOC_S_FMT",
"VIDIOC_S_FMT", format->fmt.pix.width, format->fmt.pix.width, format->fmt.pix.height, hscale, vscale);
format->fmt.pix.height, hscale, vscale);
if (cmd == VIDIOC_TRY_FMT) if (cmd == VIDIOC_TRY_FMT)
return 0; return 0;
...@@ -1064,7 +1059,7 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form ...@@ -1064,7 +1059,7 @@ static int em28xx_set_fmt(struct em28xx *dev, unsigned int cmd, struct v4l2_form
dev->width = width; dev->width = width;
dev->height = height; dev->height = height;
dev->frame_size = dev->width * dev->height * 2; dev->frame_size = dev->width * dev->height * 2;
dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */ dev->field_size = dev->frame_size >> 1;
dev->bytesperline = dev->width * 2; dev->bytesperline = dev->width * 2;
dev->hscale = hscale; dev->hscale = hscale;
dev->vscale = vscale; dev->vscale = vscale;
...@@ -1092,374 +1087,367 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp, ...@@ -1092,374 +1087,367 @@ static int em28xx_do_ioctl(struct inode *inode, struct file *filp,
switch (cmd) { switch (cmd) {
/* ---------- tv norms ---------- */ /* ---------- tv norms ---------- */
case VIDIOC_ENUMSTD: case VIDIOC_ENUMSTD:
{ {
struct v4l2_standard *e = arg; struct v4l2_standard *e = arg;
unsigned int i; unsigned int i;
i = e->index; i = e->index;
if (i >= TVNORMS) if (i >= TVNORMS)
return -EINVAL; return -EINVAL;
ret = v4l2_video_std_construct(e, tvnorms[e->index].id, ret = v4l2_video_std_construct(e, tvnorms[e->index].id,
tvnorms[e->index].name); tvnorms[e->index].name);
e->index = i; e->index = i;
if (ret < 0) if (ret < 0)
return ret; return ret;
return 0; return 0;
} }
case VIDIOC_G_STD: case VIDIOC_G_STD:
{ {
v4l2_std_id *id = arg; v4l2_std_id *id = arg;
*id = dev->tvnorm->id; *id = dev->tvnorm->id;
return 0; return 0;
} }
case VIDIOC_S_STD: case VIDIOC_S_STD:
{ {
v4l2_std_id *id = arg; v4l2_std_id *id = arg;
unsigned int i; unsigned int i;
for (i = 0; i < TVNORMS; i++)
if (*id == tvnorms[i].id)
break;
if (i == TVNORMS)
for (i = 0; i < TVNORMS; i++) for (i = 0; i < TVNORMS; i++)
if (*id == tvnorms[i].id) if (*id & tvnorms[i].id)
break; break;
if (i == TVNORMS) if (i == TVNORMS)
for (i = 0; i < TVNORMS; i++) return -EINVAL;
if (*id & tvnorms[i].id)
break;
if (i == TVNORMS)
return -EINVAL;
down(&dev->lock); down(&dev->lock);
dev->tvnorm = &tvnorms[i]; dev->tvnorm = &tvnorms[i];
em28xx_set_norm(dev, dev->width, dev->height); em28xx_set_norm(dev, dev->width, dev->height);
em28xx_i2c_call_clients(dev, DECODER_SET_NORM, em28xx_i2c_call_clients(dev, DECODER_SET_NORM,
&tvnorms[i].mode); &tvnorms[i].mode);
em28xx_i2c_call_clients(dev, VIDIOC_S_STD, em28xx_i2c_call_clients(dev, VIDIOC_S_STD,
&dev->tvnorm->id); &dev->tvnorm->id);
up(&dev->lock); up(&dev->lock);
return 0; return 0;
} }
/* ------ input switching ---------- */ /* ------ input switching ---------- */
case VIDIOC_ENUMINPUT: case VIDIOC_ENUMINPUT:
{ {
struct v4l2_input *i = arg; struct v4l2_input *i = arg;
unsigned int n; unsigned int n;
static const char *iname[] = { static const char *iname[] = {
[EM28XX_VMUX_COMPOSITE1] = "Composite1", [EM28XX_VMUX_COMPOSITE1] = "Composite1",
[EM28XX_VMUX_COMPOSITE2] = "Composite2", [EM28XX_VMUX_COMPOSITE2] = "Composite2",
[EM28XX_VMUX_COMPOSITE3] = "Composite3", [EM28XX_VMUX_COMPOSITE3] = "Composite3",
[EM28XX_VMUX_COMPOSITE4] = "Composite4", [EM28XX_VMUX_COMPOSITE4] = "Composite4",
[EM28XX_VMUX_SVIDEO] = "S-Video", [EM28XX_VMUX_SVIDEO] = "S-Video",
[EM28XX_VMUX_TELEVISION] = "Television", [EM28XX_VMUX_TELEVISION] = "Television",
[EM28XX_VMUX_CABLE] = "Cable TV", [EM28XX_VMUX_CABLE] = "Cable TV",
[EM28XX_VMUX_DVB] = "DVB", [EM28XX_VMUX_DVB] = "DVB",
[EM28XX_VMUX_DEBUG] = "for debug only", [EM28XX_VMUX_DEBUG] = "for debug only",
}; };
n = i->index; n = i->index;
if (n >= MAX_EM28XX_INPUT) if (n >= MAX_EM28XX_INPUT)
return -EINVAL; return -EINVAL;
if (0 == INPUT(n)->type) if (0 == INPUT(n)->type)
return -EINVAL; return -EINVAL;
memset(i, 0, sizeof(*i)); memset(i, 0, sizeof(*i));
i->index = n; i->index = n;
i->type = V4L2_INPUT_TYPE_CAMERA; i->type = V4L2_INPUT_TYPE_CAMERA;
strcpy(i->name, iname[INPUT(n)->type]); strcpy(i->name, iname[INPUT(n)->type]);
if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) || if ((EM28XX_VMUX_TELEVISION == INPUT(n)->type) ||
(EM28XX_VMUX_CABLE == INPUT(n)->type)) (EM28XX_VMUX_CABLE == INPUT(n)->type))
i->type = V4L2_INPUT_TYPE_TUNER; i->type = V4L2_INPUT_TYPE_TUNER;
for (n = 0; n < ARRAY_SIZE(tvnorms); n++) for (n = 0; n < ARRAY_SIZE(tvnorms); n++)
i->std |= tvnorms[n].id; i->std |= tvnorms[n].id;
return 0; return 0;
} }
case VIDIOC_G_INPUT: case VIDIOC_G_INPUT:
{ {
int *i = arg; int *i = arg;
*i = dev->ctl_input; *i = dev->ctl_input;
return 0;
}
return 0;
}
case VIDIOC_S_INPUT: case VIDIOC_S_INPUT:
{ {
int *index = arg; int *index = arg;
if (*index >= MAX_EM28XX_INPUT)
return -EINVAL;
if (0 == INPUT(*index)->type)
return -EINVAL;
down(&dev->lock); if (*index >= MAX_EM28XX_INPUT)
video_mux(dev, *index); return -EINVAL;
up(&dev->lock); if (0 == INPUT(*index)->type)
return -EINVAL;
return 0; down(&dev->lock);
} video_mux(dev, *index);
up(&dev->lock);
return 0;
}
case VIDIOC_G_AUDIO: case VIDIOC_G_AUDIO:
{ {
struct v4l2_audio *a = arg; struct v4l2_audio *a = arg;
unsigned int index = a->index; unsigned int index = a->index;
if (a->index > 1) if (a->index > 1)
return -EINVAL; return -EINVAL;
memset(a, 0, sizeof(*a)); memset(a, 0, sizeof(*a));
index = dev->ctl_ainput; index = dev->ctl_ainput;
if (index == 0) { if (index == 0) {
strcpy(a->name, "Television"); strcpy(a->name, "Television");
} else { } else {
strcpy(a->name, "Line In"); strcpy(a->name, "Line In");
}
a->capability = V4L2_AUDCAP_STEREO;
a->index = index;
return 0;
} }
a->capability = V4L2_AUDCAP_STEREO;
a->index = index;
return 0;
}
case VIDIOC_S_AUDIO: case VIDIOC_S_AUDIO:
{ {
struct v4l2_audio *a = arg; struct v4l2_audio *a = arg;
if (a->index != dev->ctl_ainput)
return -EINVAL;
return 0; if (a->index != dev->ctl_ainput)
} return -EINVAL;
return 0;
}
/* --- controls ---------------------------------------------- */ /* --- controls ---------------------------------------------- */
case VIDIOC_QUERYCTRL: case VIDIOC_QUERYCTRL:
{ {
struct v4l2_queryctrl *qc = arg; struct v4l2_queryctrl *qc = arg;
int i, id=qc->id; int i, id=qc->id;
memset(qc,0,sizeof(*qc)); memset(qc,0,sizeof(*qc));
qc->id=id; qc->id=id;
if (!dev->has_msp34xx) { if (!dev->has_msp34xx) {
for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
if (qc->id && qc->id == em28xx_qctrl[i].id) { if (qc->id && qc->id == em28xx_qctrl[i].id) {
memcpy(qc, &(em28xx_qctrl[i]), memcpy(qc, &(em28xx_qctrl[i]),
sizeof(*qc)); sizeof(*qc));
return 0;
}
}
}
if (dev->decoder == EM28XX_TVP5150) {
em28xx_i2c_call_clients(dev,cmd,qc);
if (qc->type)
return 0;
else
return -EINVAL;
}
for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) {
if (qc->id && qc->id == saa711x_qctrl[i].id) {
memcpy(qc, &(saa711x_qctrl[i]),
sizeof(*qc));
return 0; return 0;
} }
} }
}
return -EINVAL; if (dev->decoder == EM28XX_TVP5150) {
em28xx_i2c_call_clients(dev,cmd,qc);
if (qc->type)
return 0;
else
return -EINVAL;
}
for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) {
if (qc->id && qc->id == saa711x_qctrl[i].id) {
memcpy(qc, &(saa711x_qctrl[i]),
sizeof(*qc));
return 0;
}
} }
return -EINVAL;
}
case VIDIOC_G_CTRL: case VIDIOC_G_CTRL:
{ {
struct v4l2_control *ctrl = arg; struct v4l2_control *ctrl = arg;
int retval=-EINVAL; int retval=-EINVAL;
if (!dev->has_msp34xx)
retval=em28xx_get_ctrl(dev, ctrl);
if (retval==-EINVAL) {
if (dev->decoder == EM28XX_TVP5150) {
em28xx_i2c_call_clients(dev,cmd,arg);
return 0;
}
return saa711x_get_ctrl(dev, ctrl); if (!dev->has_msp34xx)
} else return retval; retval=em28xx_get_ctrl(dev, ctrl);
} if (retval==-EINVAL) {
if (dev->decoder == EM28XX_TVP5150) {
em28xx_i2c_call_clients(dev,cmd,arg);
return 0;
}
return saa711x_get_ctrl(dev, ctrl);
} else return retval;
}
case VIDIOC_S_CTRL: case VIDIOC_S_CTRL:
{ {
struct v4l2_control *ctrl = arg; struct v4l2_control *ctrl = arg;
u8 i; u8 i;
if (!dev->has_msp34xx){ if (!dev->has_msp34xx){
for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
if (ctrl->id == em28xx_qctrl[i].id) { if (ctrl->id == em28xx_qctrl[i].id) {
if (ctrl->value < if (ctrl->value <
em28xx_qctrl[i].minimum em28xx_qctrl[i].minimum
|| ctrl->value > || ctrl->value >
em28xx_qctrl[i].maximum) em28xx_qctrl[i].maximum)
return -ERANGE; return -ERANGE;
return em28xx_set_ctrl(dev, ctrl); return em28xx_set_ctrl(dev, ctrl);
}
} }
} }
}
if (dev->decoder == EM28XX_TVP5150) { if (dev->decoder == EM28XX_TVP5150) {
em28xx_i2c_call_clients(dev,cmd,arg); em28xx_i2c_call_clients(dev,cmd,arg);
return 0; return 0;
} else if (!dev->has_msp34xx) { } else if (!dev->has_msp34xx) {
for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) { for (i = 0; i < ARRAY_SIZE(em28xx_qctrl); i++) {
if (ctrl->id == em28xx_qctrl[i].id) { if (ctrl->id == em28xx_qctrl[i].id) {
if (ctrl->value < if (ctrl->value <
em28xx_qctrl[i].minimum em28xx_qctrl[i].minimum
|| ctrl->value > || ctrl->value >
em28xx_qctrl[i].maximum) em28xx_qctrl[i].maximum)
return -ERANGE; return -ERANGE;
return em28xx_set_ctrl(dev, ctrl); return em28xx_set_ctrl(dev, ctrl);
}
} }
for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) { }
if (ctrl->id == saa711x_qctrl[i].id) { for (i = 0; i < ARRAY_SIZE(saa711x_qctrl); i++) {
if (ctrl->value < if (ctrl->id == saa711x_qctrl[i].id) {
saa711x_qctrl[i].minimum if (ctrl->value <
|| ctrl->value > saa711x_qctrl[i].minimum
saa711x_qctrl[i].maximum) || ctrl->value >
return -ERANGE; saa711x_qctrl[i].maximum)
return saa711x_set_ctrl(dev, ctrl); return -ERANGE;
} return saa711x_set_ctrl(dev, ctrl);
} }
} }
return -EINVAL;
} }
/* --- tuner ioctls ------------------------------------------ */ return -EINVAL;
}
/* --- tuner ioctls ------------------------------------------ */
case VIDIOC_G_TUNER: case VIDIOC_G_TUNER:
{ {
struct v4l2_tuner *t = arg; struct v4l2_tuner *t = arg;
int status = 0; int status = 0;
if (0 != t->index) if (0 != t->index)
return -EINVAL; return -EINVAL;
memset(t, 0, sizeof(*t)); memset(t, 0, sizeof(*t));
strcpy(t->name, "Tuner"); strcpy(t->name, "Tuner");
t->type = V4L2_TUNER_ANALOG_TV; t->type = V4L2_TUNER_ANALOG_TV;
t->capability = V4L2_TUNER_CAP_NORM; t->capability = V4L2_TUNER_CAP_NORM;
t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
/* t->signal = 0xffff;*/ /* t->signal = 0xffff;*/
/* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/ /* em28xx_i2c_call_clients(dev,VIDIOC_G_TUNER,t);*/
/* No way to get signal strength? */ /* No way to get signal strength? */
down(&dev->lock); down(&dev->lock);
em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, em28xx_i2c_call_clients(dev, DECODER_GET_STATUS,
&status); &status);
up(&dev->lock); up(&dev->lock);
t->signal = t->signal =
(status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal, em28xx_videodbg("VIDIO_G_TUNER: signal=%x, afc=%x\n", t->signal,
t->afc); t->afc);
return 0; return 0;
} }
case VIDIOC_S_TUNER: case VIDIOC_S_TUNER:
{ {
struct v4l2_tuner *t = arg; struct v4l2_tuner *t = arg;
int status = 0; int status = 0;
if (0 != t->index) if (0 != t->index)
return -EINVAL; return -EINVAL;
memset(t, 0, sizeof(*t)); memset(t, 0, sizeof(*t));
strcpy(t->name, "Tuner"); strcpy(t->name, "Tuner");
t->type = V4L2_TUNER_ANALOG_TV; t->type = V4L2_TUNER_ANALOG_TV;
t->capability = V4L2_TUNER_CAP_NORM; t->capability = V4L2_TUNER_CAP_NORM;
t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */ t->rangehigh = 0xffffffffUL; /* FIXME: set correct range */
/* t->signal = 0xffff; */ /* t->signal = 0xffff; */
/* No way to get signal strength? */ /* No way to get signal strength? */
down(&dev->lock); down(&dev->lock);
em28xx_i2c_call_clients(dev, DECODER_GET_STATUS, em28xx_i2c_call_clients(dev, DECODER_GET_STATUS,
&status); &status);
up(&dev->lock); up(&dev->lock);
t->signal = t->signal =
(status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0; (status & DECODER_STATUS_GOOD) != 0 ? 0xffff : 0;
em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n", em28xx_videodbg("VIDIO_S_TUNER: signal=%x, afc=%x\n",
t->signal, t->afc); t->signal, t->afc);
return 0; return 0;
} }
case VIDIOC_G_FREQUENCY: case VIDIOC_G_FREQUENCY:
{ {
struct v4l2_frequency *f = arg; struct v4l2_frequency *f = arg;
memset(f, 0, sizeof(*f)); memset(f, 0, sizeof(*f));
f->type = V4L2_TUNER_ANALOG_TV; f->type = V4L2_TUNER_ANALOG_TV;
f->frequency = dev->ctl_freq; f->frequency = dev->ctl_freq;
return 0; return 0;
} }
case VIDIOC_S_FREQUENCY: case VIDIOC_S_FREQUENCY:
{ {
struct v4l2_frequency *f = arg; struct v4l2_frequency *f = arg;
if (0 != f->tuner)
return -EINVAL;
if (V4L2_TUNER_ANALOG_TV != f->type) if (0 != f->tuner)
return -EINVAL; return -EINVAL;
down(&dev->lock); if (V4L2_TUNER_ANALOG_TV != f->type)
dev->ctl_freq = f->frequency; return -EINVAL;
em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
up(&dev->lock);
return 0;
}
down(&dev->lock);
dev->ctl_freq = f->frequency;
em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, f);
up(&dev->lock);
return 0;
}
case VIDIOC_CROPCAP: case VIDIOC_CROPCAP:
{ {
struct v4l2_cropcap *cc = arg; struct v4l2_cropcap *cc = arg;
if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
return -EINVAL; return -EINVAL;
cc->bounds.left = 0; cc->bounds.left = 0;
cc->bounds.top = 0; cc->bounds.top = 0;
cc->bounds.width = dev->width; cc->bounds.width = dev->width;
cc->bounds.height = dev->height; cc->bounds.height = dev->height;
cc->defrect = cc->bounds; cc->defrect = cc->bounds;
cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */ cc->pixelaspect.numerator = 54; /* 4:3 FIXME: remove magic numbers */
cc->pixelaspect.denominator = 59; cc->pixelaspect.denominator = 59;
return 0; return 0;
} }
case VIDIOC_STREAMON: case VIDIOC_STREAMON:
{ {
int *type = arg; int *type = arg;
if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
|| dev->io != IO_MMAP) || dev->io != IO_MMAP)
return -EINVAL; return -EINVAL;
if (list_empty(&dev->inqueue)) if (list_empty(&dev->inqueue))
return -EINVAL; return -EINVAL;
dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ dev->stream = STREAM_ON; /* FIXME: Start video capture here? */
em28xx_videodbg("VIDIOC_STREAMON: starting stream\n"); em28xx_videodbg("VIDIOC_STREAMON: starting stream\n");
return 0; return 0;
} }
case VIDIOC_STREAMOFF: case VIDIOC_STREAMOFF:
{ {
int *type = arg; int *type = arg;
int ret; int ret;
if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
|| dev->io != IO_MMAP)
return -EINVAL;
if (dev->stream == STREAM_ON) { if (*type != V4L2_BUF_TYPE_VIDEO_CAPTURE
em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n"); || dev->io != IO_MMAP)
if ((ret = em28xx_stream_interrupt(dev))) return -EINVAL;
return ret;
}
em28xx_empty_framequeues(dev);
return 0; if (dev->stream == STREAM_ON) {
em28xx_videodbg ("VIDIOC_STREAMOFF: interrupting stream\n");
if ((ret = em28xx_stream_interrupt(dev)))
return ret;
} }
em28xx_empty_framequeues(dev);
return 0;
}
default: default:
return v4l_compat_translate_ioctl(inode, filp, cmd, arg, return v4l_compat_translate_ioctl(inode, filp, cmd, arg,
driver_ioctl); driver_ioctl);
...@@ -1489,40 +1477,38 @@ static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp, ...@@ -1489,40 +1477,38 @@ static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp,
/* --- capabilities ------------------------------------------ */ /* --- capabilities ------------------------------------------ */
case VIDIOC_QUERYCAP: case VIDIOC_QUERYCAP:
{ {
struct v4l2_capability *cap = arg; struct v4l2_capability *cap = arg;
memset(cap, 0, sizeof(*cap)); memset(cap, 0, sizeof(*cap));
strlcpy(cap->driver, "em28xx", sizeof(cap->driver)); strlcpy(cap->driver, "em28xx", sizeof(cap->driver));
strlcpy(cap->card, em28xx_boards[dev->model].name, strlcpy(cap->card, em28xx_boards[dev->model].name,
sizeof(cap->card)); sizeof(cap->card));
strlcpy(cap->bus_info, dev->udev->dev.bus_id, strlcpy(cap->bus_info, dev->udev->dev.bus_id,
sizeof(cap->bus_info)); sizeof(cap->bus_info));
cap->version = EM28XX_VERSION_CODE; cap->version = EM28XX_VERSION_CODE;
cap->capabilities = cap->capabilities =
V4L2_CAP_SLICED_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE |
V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VIDEO_CAPTURE |
V4L2_CAP_AUDIO | V4L2_CAP_AUDIO |
V4L2_CAP_READWRITE | V4L2_CAP_STREAMING; V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
if (dev->has_tuner) if (dev->has_tuner)
cap->capabilities |= V4L2_CAP_TUNER; cap->capabilities |= V4L2_CAP_TUNER;
return 0; return 0;
} }
/* --- capture ioctls ---------------------------------------- */
/* --- capture ioctls ---------------------------------------- */
case VIDIOC_ENUM_FMT: case VIDIOC_ENUM_FMT:
{ {
struct v4l2_fmtdesc *fmtd = arg; struct v4l2_fmtdesc *fmtd = arg;
if (fmtd->index != 0)
return -EINVAL;
memset(fmtd, 0, sizeof(*fmtd));
fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
strcpy(fmtd->description, "Packed YUY2");
fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
return 0;
}
if (fmtd->index != 0)
return -EINVAL;
memset(fmtd, 0, sizeof(*fmtd));
fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
strcpy(fmtd->description, "Packed YUY2");
fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
memset(fmtd->reserved, 0, sizeof(fmtd->reserved));
return 0;
}
case VIDIOC_G_FMT: case VIDIOC_G_FMT:
return em28xx_get_fmt(dev, (struct v4l2_format *) arg); return em28xx_get_fmt(dev, (struct v4l2_format *) arg);
...@@ -1531,131 +1517,130 @@ static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp, ...@@ -1531,131 +1517,130 @@ static int em28xx_video_do_ioctl(struct inode *inode, struct file *filp,
return em28xx_set_fmt(dev, cmd, (struct v4l2_format *)arg); return em28xx_set_fmt(dev, cmd, (struct v4l2_format *)arg);
case VIDIOC_REQBUFS: case VIDIOC_REQBUFS:
{ {
struct v4l2_requestbuffers *rb = arg; struct v4l2_requestbuffers *rb = arg;
u32 i; u32 i;
int ret; int ret;
if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
rb->memory != V4L2_MEMORY_MMAP)
return -EINVAL;
if (dev->io == IO_READ) { if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
em28xx_videodbg ("method is set to read;" rb->memory != V4L2_MEMORY_MMAP)
" close and open the device again to" return -EINVAL;
" choose the mmap I/O method\n");
return -EINVAL;
}
for (i = 0; i < dev->num_frames; i++) if (dev->io == IO_READ) {
if (dev->frame[i].vma_use_count) { em28xx_videodbg ("method is set to read;"
em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n"); " close and open the device again to"
return -EINVAL; " choose the mmap I/O method\n");
} return -EINVAL;
}
if (dev->stream == STREAM_ON) { for (i = 0; i < dev->num_frames; i++)
em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n"); if (dev->frame[i].vma_use_count) {
if ((ret = em28xx_stream_interrupt(dev))) em28xx_videodbg ("VIDIOC_REQBUFS failed; previous buffers are still mapped\n");
return ret; return -EINVAL;
} }
em28xx_empty_framequeues(dev); if (dev->stream == STREAM_ON) {
em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
if ((ret = em28xx_stream_interrupt(dev)))
return ret;
}
em28xx_release_buffers(dev); em28xx_empty_framequeues(dev);
if (rb->count)
rb->count =
em28xx_request_buffers(dev, rb->count);
dev->frame_current = NULL; em28xx_release_buffers(dev);
if (rb->count)
rb->count =
em28xx_request_buffers(dev, rb->count);
em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n", dev->frame_current = NULL;
rb->count);
dev->io = rb->count ? IO_MMAP : IO_NONE;
return 0;
}
em28xx_videodbg ("VIDIOC_REQBUFS: setting io method to mmap: num bufs %i\n",
rb->count);
dev->io = rb->count ? IO_MMAP : IO_NONE;
return 0;
}
case VIDIOC_QUERYBUF: case VIDIOC_QUERYBUF:
{ {
struct v4l2_buffer *b = arg; struct v4l2_buffer *b = arg;
if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
b->index >= dev->num_frames || dev->io != IO_MMAP) b->index >= dev->num_frames || dev->io != IO_MMAP)
return -EINVAL; return -EINVAL;
memcpy(b, &dev->frame[b->index].buf, sizeof(*b)); memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
if (dev->frame[b->index].vma_use_count) { if (dev->frame[b->index].vma_use_count) {
b->flags |= V4L2_BUF_FLAG_MAPPED; b->flags |= V4L2_BUF_FLAG_MAPPED;
}
if (dev->frame[b->index].state == F_DONE)
b->flags |= V4L2_BUF_FLAG_DONE;
else if (dev->frame[b->index].state != F_UNUSED)
b->flags |= V4L2_BUF_FLAG_QUEUED;
return 0;
} }
if (dev->frame[b->index].state == F_DONE)
b->flags |= V4L2_BUF_FLAG_DONE;
else if (dev->frame[b->index].state != F_UNUSED)
b->flags |= V4L2_BUF_FLAG_QUEUED;
return 0;
}
case VIDIOC_QBUF: case VIDIOC_QBUF:
{ {
struct v4l2_buffer *b = arg; struct v4l2_buffer *b = arg;
unsigned long lock_flags; unsigned long lock_flags;
if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
b->index >= dev->num_frames || dev->io != IO_MMAP) { b->index >= dev->num_frames || dev->io != IO_MMAP) {
return -EINVAL; return -EINVAL;
} }
if (dev->frame[b->index].state != F_UNUSED) { if (dev->frame[b->index].state != F_UNUSED) {
return -EAGAIN; return -EAGAIN;
} }
dev->frame[b->index].state = F_QUEUED; dev->frame[b->index].state = F_QUEUED;
/* add frame to fifo */ /* add frame to fifo */
spin_lock_irqsave(&dev->queue_lock, lock_flags); spin_lock_irqsave(&dev->queue_lock, lock_flags);
list_add_tail(&dev->frame[b->index].frame, list_add_tail(&dev->frame[b->index].frame,
&dev->inqueue); &dev->inqueue);
spin_unlock_irqrestore(&dev->queue_lock, lock_flags); spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
return 0; return 0;
} }
case VIDIOC_DQBUF: case VIDIOC_DQBUF:
{ {
struct v4l2_buffer *b = arg; struct v4l2_buffer *b = arg;
struct em28xx_frame_t *f; struct em28xx_frame_t *f;
unsigned long lock_flags; unsigned long lock_flags;
int ret = 0; int ret = 0;
if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE
|| dev->io != IO_MMAP) || dev->io != IO_MMAP)
return -EINVAL; return -EINVAL;
if (list_empty(&dev->outqueue)) { if (list_empty(&dev->outqueue)) {
if (dev->stream == STREAM_OFF) if (dev->stream == STREAM_OFF)
return -EINVAL; return -EINVAL;
if (filp->f_flags & O_NONBLOCK) if (filp->f_flags & O_NONBLOCK)
return -EAGAIN; return -EAGAIN;
ret = wait_event_interruptible ret = wait_event_interruptible
(dev->wait_frame, (dev->wait_frame,
(!list_empty(&dev->outqueue)) || (!list_empty(&dev->outqueue)) ||
(dev->state & DEV_DISCONNECTED)); (dev->state & DEV_DISCONNECTED));
if (ret) if (ret)
return ret; return ret;
if (dev->state & DEV_DISCONNECTED) if (dev->state & DEV_DISCONNECTED)
return -ENODEV; return -ENODEV;
} }
spin_lock_irqsave(&dev->queue_lock, lock_flags); spin_lock_irqsave(&dev->queue_lock, lock_flags);
f = list_entry(dev->outqueue.next, f = list_entry(dev->outqueue.next,
struct em28xx_frame_t, frame); struct em28xx_frame_t, frame);
list_del(dev->outqueue.next); list_del(dev->outqueue.next);
spin_unlock_irqrestore(&dev->queue_lock, lock_flags); spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
f->state = F_UNUSED; f->state = F_UNUSED;
memcpy(b, &f->buf, sizeof(*b)); memcpy(b, &f->buf, sizeof(*b));
if (f->vma_use_count) if (f->vma_use_count)
b->flags |= V4L2_BUF_FLAG_MAPPED; b->flags |= V4L2_BUF_FLAG_MAPPED;
return 0; return 0;
} }
default: default:
return em28xx_do_ioctl(inode, filp, dev, cmd, arg, return em28xx_do_ioctl(inode, filp, dev, cmd, arg,
em28xx_video_do_ioctl); em28xx_video_do_ioctl);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment