665 unsigned int cmd,
void __user *arg)
669 DECLARE_WAITQUEUE(wait, current);
671 dev = video_get_drvdata(video_devdata(fp));
673#if (CONFIG_STK11XX_DEBUG == 1)
674 v4l_printk_ioctl(cmd);
678 case VIDIOC_QUERYCAP:
680 struct v4l2_capability *cap = arg;
684 memset(cap, 0,
sizeof(*cap));
685 strlcpy(cap->driver,
"stk11xx",
sizeof(cap->driver));
687 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | V4L2_CAP_STREAMING;
690 if (usb_make_path(dev->
udev, cap->bus_info,
sizeof(cap->bus_info)) < 0)
691 strlcpy(cap->bus_info, dev->
vdev->name,
sizeof(cap->bus_info));
695 case VIDIOC_ENUMINPUT:
697 struct v4l2_input *i = arg;
699 STK_DEBUG(
"VIDIOC_ENUMINPUT %d\n", i->index);
704 strlcpy(i->name,
"USB",
sizeof(i->name));
712 strlcpy(i->name,
"Input1",
sizeof(i->name));
715 strlcpy(i->name,
"Input2",
sizeof(i->name));
718 strlcpy(i->name,
"Input3",
sizeof(i->name));
721 strlcpy(i->name,
"Input4",
sizeof(i->name));
726 i->type = V4L2_INPUT_TYPE_CAMERA;
740 struct v4l2_input *i = arg;
755 case VIDIOC_QUERYCTRL:
759 struct v4l2_queryctrl *c = arg;
761 STK_DEBUG(
"VIDIOC_QUERYCTRL id = %d\n", c->id);
765 for (i=0; i<nbr; i++) {
771 case V4L2_CID_BRIGHTNESS:
772 c->default_value = dev->
vsettings.default_brightness;
774 case V4L2_CID_WHITENESS:
775 c->default_value = dev->
vsettings.default_whiteness;
777 case V4L2_CID_SATURATION:
778 c->default_value = dev->
vsettings.default_colour;
780 case V4L2_CID_CONTRAST:
781 c->default_value = dev->
vsettings.default_contrast;
784 c->default_value = dev->
vsettings.default_hflip;
787 c->default_value = dev->
vsettings.default_vflip;
801 struct v4l2_control *c = arg;
806 case V4L2_CID_BRIGHTNESS:
810 case V4L2_CID_WHITENESS:
818 case V4L2_CID_SATURATION:
822 case V4L2_CID_CONTRAST:
843 struct v4l2_control *c = arg;
845 STK_DEBUG(
"SET CTRL id=%d value=%d\n", c->id, c->value);
848 case V4L2_CID_BRIGHTNESS:
856 case V4L2_CID_SATURATION:
860 case V4L2_CID_CONTRAST:
880 case VIDIOC_ENUM_FMT:
883 struct v4l2_fmtdesc *fmtd = arg;
885 STK_DEBUG(
"VIDIOC_ENUM_FMT %d\n", fmtd->index);
889 memset(fmtd, 0,
sizeof(*fmtd));
891 fmtd->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
897 fmtd->pixelformat = V4L2_PIX_FMT_RGB24;
899 strcpy(fmtd->description,
"rgb24");
904 fmtd->pixelformat = V4L2_PIX_FMT_RGB32;
906 strcpy(fmtd->description,
"rgb32");
911 fmtd->pixelformat = V4L2_PIX_FMT_BGR24;
913 strcpy(fmtd->description,
"bgr24");
918 fmtd->pixelformat = V4L2_PIX_FMT_BGR32;
920 strcpy(fmtd->description,
"bgr32");
925 fmtd->pixelformat = V4L2_PIX_FMT_UYVY;
927 strcpy(fmtd->description,
"uyvy");
932 fmtd->pixelformat = V4L2_PIX_FMT_YUYV;
934 strcpy(fmtd->description,
"yuyv");
945 struct v4l2_format *fmtd = arg;
946 struct v4l2_pix_format pix_format;
950 if (fmtd->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
953 pix_format.width = dev->view.
x;
954 pix_format.height = dev->view.
y;
955 pix_format.field = V4L2_FIELD_NONE;
956 pix_format.colorspace = V4L2_COLORSPACE_SRGB;
960 case STK11XX_PALETTE_RGB24:
961 pix_format.pixelformat = V4L2_PIX_FMT_RGB24;
962 pix_format.sizeimage = pix_format.width * pix_format.height * 3;
963 pix_format.bytesperline = 3 * pix_format.width;
966 case STK11XX_PALETTE_RGB32:
967 pix_format.pixelformat = V4L2_PIX_FMT_RGB32;
968 pix_format.sizeimage = pix_format.width * pix_format.height * 4;
969 pix_format.bytesperline = 4 * pix_format.width;
972 case STK11XX_PALETTE_BGR24:
973 pix_format.pixelformat = V4L2_PIX_FMT_BGR24;
974 pix_format.sizeimage = pix_format.width * pix_format.height * 3;
975 pix_format.bytesperline = 3 * pix_format.width;
978 case STK11XX_PALETTE_BGR32:
979 pix_format.pixelformat = V4L2_PIX_FMT_BGR32;
980 pix_format.sizeimage = pix_format.width * pix_format.height * 4;
981 pix_format.bytesperline = 4 * pix_format.width;
984 case STK11XX_PALETTE_UYVY:
985 pix_format.pixelformat = V4L2_PIX_FMT_UYVY;
986 pix_format.sizeimage = pix_format.width * pix_format.height * 2;
987 pix_format.bytesperline = 2 * pix_format.width;
990 case STK11XX_PALETTE_YUYV:
991 pix_format.pixelformat = V4L2_PIX_FMT_YUYV;
992 pix_format.sizeimage = pix_format.width * pix_format.height * 2;
993 pix_format.bytesperline = 2 * pix_format.width;
997 pix_format.pixelformat = 0;
998 pix_format.sizeimage = 0;
999 pix_format.bytesperline = 0;
1002 memcpy(&(fmtd->fmt.pix), &pix_format,
sizeof(pix_format));
1006 case VIDIOC_TRY_FMT:
1008 struct v4l2_format *fmtd = arg;
1012 if (fmtd->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1054 fmtd->fmt.pix.field = V4L2_FIELD_NONE;
1055 fmtd->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
1056 fmtd->fmt.pix.priv = 0;
1058 switch (fmtd->fmt.pix.pixelformat) {
1059 case V4L2_PIX_FMT_RGB24:
1060 case V4L2_PIX_FMT_BGR24:
1062 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 3;
1063 fmtd->fmt.pix.bytesperline = 3 * fmtd->fmt.pix.width;
1066 case V4L2_PIX_FMT_RGB32:
1067 case V4L2_PIX_FMT_BGR32:
1069 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 4;
1070 fmtd->fmt.pix.bytesperline = 4 * fmtd->fmt.pix.width;
1073 case V4L2_PIX_FMT_UYVY:
1074 case V4L2_PIX_FMT_YUYV:
1076 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 2;
1077 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width;
1088 struct v4l2_format *fmtd = arg;
1090 STK_DEBUG(
"SET FMT %d : %d\n", fmtd->type, fmtd->fmt.pix.pixelformat);
1092 if (fmtd->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1095 fmtd->fmt.pix.field = V4L2_FIELD_NONE;
1096 fmtd->fmt.pix.colorspace = V4L2_COLORSPACE_SRGB;
1097 fmtd->fmt.pix.priv = 0;
1099 switch (fmtd->fmt.pix.pixelformat) {
1100 case V4L2_PIX_FMT_RGB24:
1103 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 3;
1104 fmtd->fmt.pix.bytesperline = 3 * fmtd->fmt.pix.width;
1107 case V4L2_PIX_FMT_RGB32:
1110 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 4;
1111 fmtd->fmt.pix.bytesperline = 4 * fmtd->fmt.pix.width;
1114 case V4L2_PIX_FMT_BGR24:
1117 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 3;
1118 fmtd->fmt.pix.bytesperline = 3 * fmtd->fmt.pix.width;
1121 case V4L2_PIX_FMT_BGR32:
1124 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 4;
1125 fmtd->fmt.pix.bytesperline = 4 * fmtd->fmt.pix.width;
1128 case V4L2_PIX_FMT_UYVY:
1131 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 2;
1132 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width;
1135 case V4L2_PIX_FMT_YUYV:
1138 fmtd->fmt.pix.sizeimage = fmtd->fmt.pix.width * fmtd->fmt.pix.height * 2;
1139 fmtd->fmt.pix.bytesperline = 2 * fmtd->fmt.pix.width;
1146 STK_DEBUG(
"Set width=%d, height=%d\n", fmtd->fmt.pix.width, fmtd->fmt.pix.height);
1161 STK_ERROR(
"Select video mode failed !\n");
1184 case VIDIOC_QUERYSTD:
1193 v4l2_std_id *std = arg;
1197 *std = V4L2_STD_UNKNOWN;
1203 v4l2_std_id *std = arg;
1207 if (*std != V4L2_STD_UNKNOWN)
1212 case VIDIOC_ENUMSTD:
1214 struct v4l2_standard *std = arg;
1218 if (std->index != 0)
1221 std->id = V4L2_STD_UNKNOWN;
1222 strncpy(std->name,
"webcam",
sizeof(std->name));
1227 case VIDIOC_REQBUFS:
1230 struct v4l2_requestbuffers *rb = arg;
1232 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1235 if (rb->memory != V4L2_MEMORY_MMAP)
1238 nbuffers = rb->count;
1242 else if (nbuffers > dev->nbuffers)
1243 nbuffers = dev->nbuffers;
1245 rb->count = dev->nbuffers;
1249 case VIDIOC_QUERYBUF:
1252 struct v4l2_buffer *buf = arg;
1254 STK_DEBUG(
"QUERY BUFFERS %d %d\n", buf->index, dev->nbuffers);
1256 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1259 if (buf->memory != V4L2_MEMORY_MMAP)
1264 if (index < 0 || index >= dev->nbuffers)
1267 memset(buf, 0,
sizeof(
struct v4l2_buffer));
1269 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1271 buf->m.offset = index * dev->len_per_image;
1272 buf->bytesused = dev->view_size;
1273 buf->field = V4L2_FIELD_NONE;
1274 buf->memory = V4L2_MEMORY_MMAP;
1275 buf->length = dev->len_per_image;
1281 struct v4l2_buffer *buf = arg;
1285 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1288 if (buf->memory != V4L2_MEMORY_MMAP)
1291 if (buf->index < 0 || buf->index >= dev->nbuffers)
1294 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1295 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1302 struct v4l2_buffer *buf = arg;
1306 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1311 while (dev->full_frames == NULL) {
1312 if (dev->error_status) {
1314 set_current_state(TASK_RUNNING);
1316 return -dev->error_status;
1319 if (signal_pending(current)) {
1321 set_current_state(TASK_RUNNING);
1323 return -ERESTARTSYS;
1327 set_current_state(TASK_INTERRUPTIBLE);
1331 set_current_state(TASK_RUNNING);
1333 STK_DEBUG(
"VIDIOC_DQBUF : frame ready.\n");
1340 buf->index = dev->fill_image;
1341 buf->bytesused = dev->view_size;
1342 buf->flags = V4L2_BUF_FLAG_MAPPED;
1343 buf->field = V4L2_FIELD_NONE;
1344 do_gettimeofday(&buf->timestamp);
1346 buf->memory = V4L2_MEMORY_MMAP;
1347 buf->m.offset = dev->fill_image * dev->len_per_image;
1348 buf->length = dev->len_per_image;
1354 case VIDIOC_STREAMON:
1362 case VIDIOC_STREAMOFF:
1372 struct v4l2_streamparm *sp = arg;
1376 if (sp->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1379 sp->parm.capture.capability = 0;
1380 sp->parm.capture.capturemode = 0;
1381 sp->parm.capture.timeperframe.numerator = 1;
1382 sp->parm.capture.timeperframe.denominator = 30;
1383 sp->parm.capture.readbuffers = 2;
1384 sp->parm.capture.extendedmode = 0;
1389 case VIDIOC_G_AUDIO:
1394 case VIDIOC_S_AUDIO:
1399 case VIDIOC_S_TUNER:
1406 case VIDIOC_OVERLAY:
1410 case VIDIOC_G_TUNER:
1411 case VIDIOC_G_FREQUENCY:
1412 case VIDIOC_S_FREQUENCY:
1416 case VIDIOC_QUERYMENU:
1442 return -ENOIOCTLCMD;