aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/meye.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/meye.c')
-rw-r--r--drivers/media/video/meye.c1361
1 files changed, 658 insertions, 703 deletions
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 3d51fa0a52b6..e7ccbc895d7a 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -42,15 +42,10 @@
42#include <linux/meye.h> 42#include <linux/meye.h>
43 43
44MODULE_AUTHOR("Stelian Pop <stelian@popies.net>"); 44MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
45MODULE_DESCRIPTION("v4l/v4l2 driver for the MotionEye camera"); 45MODULE_DESCRIPTION("v4l2 driver for the MotionEye camera");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_VERSION(MEYE_DRIVER_VERSION); 47MODULE_VERSION(MEYE_DRIVER_VERSION);
48 48
49/* force usage of V4L1 API */
50static int forcev4l1; /* = 0 */
51module_param(forcev4l1, int, 0644);
52MODULE_PARM_DESC(forcev4l1, "force use of V4L1 instead of V4L2");
53
54/* number of grab buffers */ 49/* number of grab buffers */
55static unsigned int gbuffers = 2; 50static unsigned int gbuffers = 2;
56module_param(gbuffers, int, 0444); 51module_param(gbuffers, int, 0444);
@@ -789,7 +784,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
789{ 784{
790 u32 v; 785 u32 v;
791 int reqnr; 786 int reqnr;
792 static int sequence = 0; 787 static int sequence;
793 788
794 v = mchip_read(MCHIP_MM_INTA); 789 v = mchip_read(MCHIP_MM_INTA);
795 790
@@ -876,795 +871,735 @@ static int meye_release(struct inode *inode, struct file *file)
876 return 0; 871 return 0;
877} 872}
878 873
879static int meye_do_ioctl(struct inode *inode, struct file *file, 874static int meyeioc_g_params(struct meye_params *p)
880 unsigned int cmd, void *arg)
881{ 875{
882 switch (cmd) { 876 *p = meye.params;
877 return 0;
878}
883 879
884 case VIDIOCGCAP: { 880static int meyeioc_s_params(struct meye_params *jp)
885 struct video_capability *b = arg; 881{
886 strcpy(b->name,meye.video_dev->name); 882 if (jp->subsample > 1)
887 b->type = VID_TYPE_CAPTURE; 883 return -EINVAL;
888 b->channels = 1;
889 b->audios = 0;
890 b->maxwidth = 640;
891 b->maxheight = 480;
892 b->minwidth = 320;
893 b->minheight = 240;
894 break;
895 }
896 884
897 case VIDIOCGCHAN: { 885 if (jp->quality > 10)
898 struct video_channel *v = arg; 886 return -EINVAL;
899 v->flags = 0;
900 v->tuners = 0;
901 v->type = VIDEO_TYPE_CAMERA;
902 if (v->channel != 0)
903 return -EINVAL;
904 strcpy(v->name,"Camera");
905 break;
906 }
907 887
908 case VIDIOCSCHAN: { 888 if (jp->sharpness > 63 || jp->agc > 63 || jp->picture > 63)
909 struct video_channel *v = arg; 889 return -EINVAL;
910 if (v->channel != 0)
911 return -EINVAL;
912 break;
913 }
914 890
915 case VIDIOCGPICT: { 891 if (jp->framerate > 31)
916 struct video_picture *p = arg; 892 return -EINVAL;
917 *p = meye.picture;
918 break;
919 }
920 893
921 case VIDIOCSPICT: { 894 mutex_lock(&meye.lock);
922 struct video_picture *p = arg;
923 if (p->depth != 16)
924 return -EINVAL;
925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
926 return -EINVAL;
927 mutex_lock(&meye.lock);
928 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS,
929 p->brightness >> 10);
930 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE,
931 p->hue >> 10);
932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR,
933 p->colour >> 10);
934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST,
935 p->contrast >> 10);
936 meye.picture = *p;
937 mutex_unlock(&meye.lock);
938 break;
939 }
940 895
941 case VIDIOCSYNC: { 896 if (meye.params.subsample != jp->subsample ||
942 int *i = arg; 897 meye.params.quality != jp->quality)
943 int unused; 898 mchip_hic_stop(); /* need restart */
899
900 meye.params = *jp;
901 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
902 meye.params.sharpness);
903 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
904 meye.params.agc);
905 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
906 meye.params.picture);
907 mutex_unlock(&meye.lock);
944 908
945 if (*i < 0 || *i >= gbuffers) 909 return 0;
946 return -EINVAL; 910}
947 911
948 mutex_lock(&meye.lock); 912static int meyeioc_qbuf_capt(int *nb)
913{
914 if (!meye.grab_fbuffer)
915 return -EINVAL;
949 916
950 switch (meye.grab_buffer[*i].state) { 917 if (*nb >= gbuffers)
918 return -EINVAL;
951 919
952 case MEYE_BUF_UNUSED: 920 if (*nb < 0) {
953 mutex_unlock(&meye.lock); 921 /* stop capture */
954 return -EINVAL; 922 mchip_hic_stop();
955 case MEYE_BUF_USING: 923 return 0;
956 if (file->f_flags & O_NONBLOCK) {
957 mutex_unlock(&meye.lock);
958 return -EAGAIN;
959 }
960 if (wait_event_interruptible(meye.proc_list,
961 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
962 mutex_unlock(&meye.lock);
963 return -EINTR;
964 }
965 /* fall through */
966 case MEYE_BUF_DONE:
967 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
968 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
969 }
970 mutex_unlock(&meye.lock);
971 break;
972 } 924 }
973 925
974 case VIDIOCMCAPTURE: { 926 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
975 struct video_mmap *vm = arg; 927 return -EBUSY;
976 int restart = 0;
977
978 if (vm->frame >= gbuffers || vm->frame < 0)
979 return -EINVAL;
980 if (vm->format != VIDEO_PALETTE_YUV422 && vm->format != VIDEO_PALETTE_YUYV)
981 return -EINVAL;
982 if (vm->height * vm->width * 2 > gbufsize)
983 return -EINVAL;
984 if (!meye.grab_fbuffer)
985 return -EINVAL;
986 if (meye.grab_buffer[vm->frame].state != MEYE_BUF_UNUSED)
987 return -EBUSY;
988
989 mutex_lock(&meye.lock);
990 if (vm->width == 640 && vm->height == 480) {
991 if (meye.params.subsample) {
992 meye.params.subsample = 0;
993 restart = 1;
994 }
995 } else if (vm->width == 320 && vm->height == 240) {
996 if (!meye.params.subsample) {
997 meye.params.subsample = 1;
998 restart = 1;
999 }
1000 } else {
1001 mutex_unlock(&meye.lock);
1002 return -EINVAL;
1003 }
1004 928
1005 if (restart || meye.mchip_mode != MCHIP_HIC_MODE_CONT_OUT) 929 mutex_lock(&meye.lock);
1006 mchip_continuous_start();
1007 meye.grab_buffer[vm->frame].state = MEYE_BUF_USING;
1008 kfifo_put(meye.grabq, (unsigned char *)&vm->frame, sizeof(int));
1009 mutex_unlock(&meye.lock);
1010 break;
1011 }
1012 930
1013 case VIDIOCGMBUF: { 931 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
1014 struct video_mbuf *vm = arg; 932 mchip_cont_compression_start();
1015 int i;
1016 933
1017 memset(vm, 0 , sizeof(*vm)); 934 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
1018 vm->size = gbufsize * gbuffers; 935 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
1019 vm->frames = gbuffers; 936 mutex_unlock(&meye.lock);
1020 for (i = 0; i < gbuffers; i++)
1021 vm->offsets[i] = i * gbufsize;
1022 break;
1023 }
1024 937
1025 case MEYEIOC_G_PARAMS: { 938 return 0;
1026 struct meye_params *p = arg; 939}
1027 *p = meye.params;
1028 break;
1029 }
1030 940
1031 case MEYEIOC_S_PARAMS: { 941static int meyeioc_sync(struct file *file, void *fh, int *i)
1032 struct meye_params *jp = arg; 942{
1033 if (jp->subsample > 1) 943 int unused;
1034 return -EINVAL;
1035 if (jp->quality > 10)
1036 return -EINVAL;
1037 if (jp->sharpness > 63 || jp->agc > 63 || jp->picture > 63)
1038 return -EINVAL;
1039 if (jp->framerate > 31)
1040 return -EINVAL;
1041 mutex_lock(&meye.lock);
1042 if (meye.params.subsample != jp->subsample ||
1043 meye.params.quality != jp->quality)
1044 mchip_hic_stop(); /* need restart */
1045 meye.params = *jp;
1046 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
1047 meye.params.sharpness);
1048 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
1049 meye.params.agc);
1050 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
1051 meye.params.picture);
1052 mutex_unlock(&meye.lock);
1053 break;
1054 }
1055 944
1056 case MEYEIOC_QBUF_CAPT: { 945 if (*i < 0 || *i >= gbuffers)
1057 int *nb = arg; 946 return -EINVAL;
1058 947
1059 if (!meye.grab_fbuffer) 948 mutex_lock(&meye.lock);
1060 return -EINVAL; 949 switch (meye.grab_buffer[*i].state) {
1061 if (*nb >= gbuffers) 950
1062 return -EINVAL; 951 case MEYE_BUF_UNUSED:
1063 if (*nb < 0) {
1064 /* stop capture */
1065 mchip_hic_stop();
1066 return 0;
1067 }
1068 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
1069 return -EBUSY;
1070 mutex_lock(&meye.lock);
1071 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
1072 mchip_cont_compression_start();
1073 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
1074 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
1075 mutex_unlock(&meye.lock); 952 mutex_unlock(&meye.lock);
1076 break; 953 return -EINVAL;
954 case MEYE_BUF_USING:
955 if (file->f_flags & O_NONBLOCK) {
956 mutex_unlock(&meye.lock);
957 return -EAGAIN;
958 }
959 if (wait_event_interruptible(meye.proc_list,
960 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
961 mutex_unlock(&meye.lock);
962 return -EINTR;
963 }
964 /* fall through */
965 case MEYE_BUF_DONE:
966 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
967 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
1077 } 968 }
969 *i = meye.grab_buffer[*i].size;
970 mutex_unlock(&meye.lock);
971 return 0;
972}
1078 973
1079 case MEYEIOC_SYNC: { 974static int meyeioc_stillcapt(void)
1080 int *i = arg; 975{
1081 int unused; 976 if (!meye.grab_fbuffer)
977 return -EINVAL;
1082 978
1083 if (*i < 0 || *i >= gbuffers) 979 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1084 return -EINVAL; 980 return -EBUSY;
1085 981
1086 mutex_lock(&meye.lock); 982 mutex_lock(&meye.lock);
1087 switch (meye.grab_buffer[*i].state) { 983 meye.grab_buffer[0].state = MEYE_BUF_USING;
984 mchip_take_picture();
1088 985
1089 case MEYE_BUF_UNUSED: 986 mchip_get_picture(meye.grab_fbuffer,
1090 mutex_unlock(&meye.lock); 987 mchip_hsize() * mchip_vsize() * 2);
1091 return -EINVAL;
1092 case MEYE_BUF_USING:
1093 if (file->f_flags & O_NONBLOCK) {
1094 mutex_unlock(&meye.lock);
1095 return -EAGAIN;
1096 }
1097 if (wait_event_interruptible(meye.proc_list,
1098 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
1099 mutex_unlock(&meye.lock);
1100 return -EINTR;
1101 }
1102 /* fall through */
1103 case MEYE_BUF_DONE:
1104 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
1105 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
1106 }
1107 *i = meye.grab_buffer[*i].size;
1108 mutex_unlock(&meye.lock);
1109 break;
1110 }
1111 988
1112 case MEYEIOC_STILLCAPT: { 989 meye.grab_buffer[0].state = MEYE_BUF_DONE;
990 mutex_unlock(&meye.lock);
1113 991
1114 if (!meye.grab_fbuffer) 992 return 0;
1115 return -EINVAL; 993}
1116 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED) 994
1117 return -EBUSY; 995static int meyeioc_stilljcapt(int *len)
1118 mutex_lock(&meye.lock); 996{
1119 meye.grab_buffer[0].state = MEYE_BUF_USING; 997 if (!meye.grab_fbuffer)
998 return -EINVAL;
999
1000 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1001 return -EBUSY;
1002
1003 mutex_lock(&meye.lock);
1004 meye.grab_buffer[0].state = MEYE_BUF_USING;
1005 *len = -1;
1006
1007 while (*len == -1) {
1120 mchip_take_picture(); 1008 mchip_take_picture();
1121 mchip_get_picture( 1009 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1122 meye.grab_fbuffer,
1123 mchip_hsize() * mchip_vsize() * 2);
1124 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1125 mutex_unlock(&meye.lock);
1126 break;
1127 } 1010 }
1128 1011
1129 case MEYEIOC_STILLJCAPT: { 1012 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1130 int *len = arg; 1013 mutex_unlock(&meye.lock);
1131 1014 return 0;
1132 if (!meye.grab_fbuffer) 1015}
1133 return -EINVAL;
1134 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1135 return -EBUSY;
1136 mutex_lock(&meye.lock);
1137 meye.grab_buffer[0].state = MEYE_BUF_USING;
1138 *len = -1;
1139 while (*len == -1) {
1140 mchip_take_picture();
1141 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1142 }
1143 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1144 mutex_unlock(&meye.lock);
1145 break;
1146 }
1147 1016
1148 case VIDIOC_QUERYCAP: { 1017static int vidioc_querycap(struct file *file, void *fh,
1149 struct v4l2_capability *cap = arg; 1018 struct v4l2_capability *cap)
1019{
1020 memset(cap, 0, sizeof(*cap));
1021 strcpy(cap->driver, "meye");
1022 strcpy(cap->card, "meye");
1023 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev));
1150 1024
1151 if (forcev4l1) 1025 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) +
1152 return -EINVAL; 1026 MEYE_DRIVER_MINORVERSION;
1153 1027
1154 memset(cap, 0, sizeof(*cap)); 1028 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1155 strcpy(cap->driver, "meye"); 1029 V4L2_CAP_STREAMING;
1156 strcpy(cap->card, "meye"); 1030
1157 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev)); 1031 return 0;
1158 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) + 1032}
1159 MEYE_DRIVER_MINORVERSION; 1033
1160 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1034static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
1161 V4L2_CAP_STREAMING; 1035{
1162 break; 1036 if (i->index != 0)
1163 } 1037 return -EINVAL;
1164 1038
1165 case VIDIOC_ENUMINPUT: { 1039 memset(i, 0, sizeof(*i));
1166 struct v4l2_input *i = arg; 1040 i->index = 0;
1041 strcpy(i->name, "Camera");
1042 i->type = V4L2_INPUT_TYPE_CAMERA;
1167 1043
1168 if (i->index != 0) 1044 return 0;
1169 return -EINVAL; 1045}
1170 memset(i, 0, sizeof(*i)); 1046
1171 i->index = 0; 1047static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
1172 strcpy(i->name, "Camera"); 1048{
1173 i->type = V4L2_INPUT_TYPE_CAMERA; 1049 *i = 0;
1050 return 0;
1051}
1052
1053static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
1054{
1055 if (i != 0)
1056 return -EINVAL;
1057
1058 return 0;
1059}
1060
1061static int vidioc_queryctrl(struct file *file, void *fh,
1062 struct v4l2_queryctrl *c)
1063{
1064 switch (c->id) {
1065
1066 case V4L2_CID_BRIGHTNESS:
1067 c->type = V4L2_CTRL_TYPE_INTEGER;
1068 strcpy(c->name, "Brightness");
1069 c->minimum = 0;
1070 c->maximum = 63;
1071 c->step = 1;
1072 c->default_value = 32;
1073 c->flags = 0;
1074 break;
1075 case V4L2_CID_HUE:
1076 c->type = V4L2_CTRL_TYPE_INTEGER;
1077 strcpy(c->name, "Hue");
1078 c->minimum = 0;
1079 c->maximum = 63;
1080 c->step = 1;
1081 c->default_value = 32;
1082 c->flags = 0;
1083 break;
1084 case V4L2_CID_CONTRAST:
1085 c->type = V4L2_CTRL_TYPE_INTEGER;
1086 strcpy(c->name, "Contrast");
1087 c->minimum = 0;
1088 c->maximum = 63;
1089 c->step = 1;
1090 c->default_value = 32;
1091 c->flags = 0;
1092 break;
1093 case V4L2_CID_SATURATION:
1094 c->type = V4L2_CTRL_TYPE_INTEGER;
1095 strcpy(c->name, "Saturation");
1096 c->minimum = 0;
1097 c->maximum = 63;
1098 c->step = 1;
1099 c->default_value = 32;
1100 c->flags = 0;
1101 break;
1102 case V4L2_CID_AGC:
1103 c->type = V4L2_CTRL_TYPE_INTEGER;
1104 strcpy(c->name, "Agc");
1105 c->minimum = 0;
1106 c->maximum = 63;
1107 c->step = 1;
1108 c->default_value = 48;
1109 c->flags = 0;
1174 break; 1110 break;
1111 case V4L2_CID_MEYE_SHARPNESS:
1112 case V4L2_CID_SHARPNESS:
1113 c->type = V4L2_CTRL_TYPE_INTEGER;
1114 strcpy(c->name, "Sharpness");
1115 c->minimum = 0;
1116 c->maximum = 63;
1117 c->step = 1;
1118 c->default_value = 32;
1119
1120 /* Continue to report legacy private SHARPNESS ctrl but
1121 * say it is disabled in preference to ctrl in the spec
1122 */
1123 c->flags = (c->id == V4L2_CID_SHARPNESS) ? 0 :
1124 V4L2_CTRL_FLAG_DISABLED;
1125 break;
1126 case V4L2_CID_PICTURE:
1127 c->type = V4L2_CTRL_TYPE_INTEGER;
1128 strcpy(c->name, "Picture");
1129 c->minimum = 0;
1130 c->maximum = 63;
1131 c->step = 1;
1132 c->default_value = 0;
1133 c->flags = 0;
1134 break;
1135 case V4L2_CID_JPEGQUAL:
1136 c->type = V4L2_CTRL_TYPE_INTEGER;
1137 strcpy(c->name, "JPEG quality");
1138 c->minimum = 0;
1139 c->maximum = 10;
1140 c->step = 1;
1141 c->default_value = 8;
1142 c->flags = 0;
1143 break;
1144 case V4L2_CID_FRAMERATE:
1145 c->type = V4L2_CTRL_TYPE_INTEGER;
1146 strcpy(c->name, "Framerate");
1147 c->minimum = 0;
1148 c->maximum = 31;
1149 c->step = 1;
1150 c->default_value = 0;
1151 c->flags = 0;
1152 break;
1153 default:
1154 return -EINVAL;
1175 } 1155 }
1176 1156
1177 case VIDIOC_G_INPUT: { 1157 return 0;
1178 int *i = arg; 1158}
1179 1159
1180 *i = 0; 1160static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1161{
1162 mutex_lock(&meye.lock);
1163 switch (c->id) {
1164 case V4L2_CID_BRIGHTNESS:
1165 sony_pic_camera_command(
1166 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value);
1167 meye.picture.brightness = c->value << 10;
1168 break;
1169 case V4L2_CID_HUE:
1170 sony_pic_camera_command(
1171 SONY_PIC_COMMAND_SETCAMERAHUE, c->value);
1172 meye.picture.hue = c->value << 10;
1173 break;
1174 case V4L2_CID_CONTRAST:
1175 sony_pic_camera_command(
1176 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value);
1177 meye.picture.contrast = c->value << 10;
1178 break;
1179 case V4L2_CID_SATURATION:
1180 sony_pic_camera_command(
1181 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value);
1182 meye.picture.colour = c->value << 10;
1183 break;
1184 case V4L2_CID_AGC:
1185 sony_pic_camera_command(
1186 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1187 meye.params.agc = c->value;
1188 break;
1189 case V4L2_CID_SHARPNESS:
1190 case V4L2_CID_MEYE_SHARPNESS:
1191 sony_pic_camera_command(
1192 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1193 meye.params.sharpness = c->value;
1194 break;
1195 case V4L2_CID_PICTURE:
1196 sony_pic_camera_command(
1197 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1198 meye.params.picture = c->value;
1199 break;
1200 case V4L2_CID_JPEGQUAL:
1201 meye.params.quality = c->value;
1202 break;
1203 case V4L2_CID_FRAMERATE:
1204 meye.params.framerate = c->value;
1181 break; 1205 break;
1206 default:
1207 mutex_unlock(&meye.lock);
1208 return -EINVAL;
1182 } 1209 }
1210 mutex_unlock(&meye.lock);
1183 1211
1184 case VIDIOC_S_INPUT: { 1212 return 0;
1185 int *i = arg; 1213}
1186 1214
1187 if (*i != 0) 1215static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1188 return -EINVAL; 1216{
1217 mutex_lock(&meye.lock);
1218 switch (c->id) {
1219 case V4L2_CID_BRIGHTNESS:
1220 c->value = meye.picture.brightness >> 10;
1221 break;
1222 case V4L2_CID_HUE:
1223 c->value = meye.picture.hue >> 10;
1224 break;
1225 case V4L2_CID_CONTRAST:
1226 c->value = meye.picture.contrast >> 10;
1227 break;
1228 case V4L2_CID_SATURATION:
1229 c->value = meye.picture.colour >> 10;
1230 break;
1231 case V4L2_CID_AGC:
1232 c->value = meye.params.agc;
1233 break;
1234 case V4L2_CID_SHARPNESS:
1235 case V4L2_CID_MEYE_SHARPNESS:
1236 c->value = meye.params.sharpness;
1189 break; 1237 break;
1238 case V4L2_CID_PICTURE:
1239 c->value = meye.params.picture;
1240 break;
1241 case V4L2_CID_JPEGQUAL:
1242 c->value = meye.params.quality;
1243 break;
1244 case V4L2_CID_FRAMERATE:
1245 c->value = meye.params.framerate;
1246 break;
1247 default:
1248 mutex_unlock(&meye.lock);
1249 return -EINVAL;
1190 } 1250 }
1251 mutex_unlock(&meye.lock);
1191 1252
1192 case VIDIOC_QUERYCTRL: { 1253 return 0;
1193 struct v4l2_queryctrl *c = arg; 1254}
1194 1255
1195 switch (c->id) { 1256static int vidioc_enum_fmt_cap(struct file *file, void *fh,
1257 struct v4l2_fmtdesc *f)
1258{
1259 if (f->index > 1)
1260 return -EINVAL;
1196 1261
1197 case V4L2_CID_BRIGHTNESS: 1262 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1198 c->type = V4L2_CTRL_TYPE_INTEGER; 1263 return -EINVAL;
1199 strcpy(c->name, "Brightness"); 1264
1200 c->minimum = 0; 1265 if (f->index == 0) {
1201 c->maximum = 63; 1266 /* standard YUV 422 capture */
1202 c->step = 1; 1267 memset(f, 0, sizeof(*f));
1203 c->default_value = 32; 1268 f->index = 0;
1204 c->flags = 0; 1269 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1205 break; 1270 f->flags = 0;
1206 case V4L2_CID_HUE: 1271 strcpy(f->description, "YUV422");
1207 c->type = V4L2_CTRL_TYPE_INTEGER; 1272 f->pixelformat = V4L2_PIX_FMT_YUYV;
1208 strcpy(c->name, "Hue"); 1273 } else {
1209 c->minimum = 0; 1274 /* compressed MJPEG capture */
1210 c->maximum = 63; 1275 memset(f, 0, sizeof(*f));
1211 c->step = 1; 1276 f->index = 1;
1212 c->default_value = 32; 1277 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1213 c->flags = 0; 1278 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1214 break; 1279 strcpy(f->description, "MJPEG");
1215 case V4L2_CID_CONTRAST: 1280 f->pixelformat = V4L2_PIX_FMT_MJPEG;
1216 c->type = V4L2_CTRL_TYPE_INTEGER;
1217 strcpy(c->name, "Contrast");
1218 c->minimum = 0;
1219 c->maximum = 63;
1220 c->step = 1;
1221 c->default_value = 32;
1222 c->flags = 0;
1223 break;
1224 case V4L2_CID_SATURATION:
1225 c->type = V4L2_CTRL_TYPE_INTEGER;
1226 strcpy(c->name, "Saturation");
1227 c->minimum = 0;
1228 c->maximum = 63;
1229 c->step = 1;
1230 c->default_value = 32;
1231 c->flags = 0;
1232 break;
1233 case V4L2_CID_AGC:
1234 c->type = V4L2_CTRL_TYPE_INTEGER;
1235 strcpy(c->name, "Agc");
1236 c->minimum = 0;
1237 c->maximum = 63;
1238 c->step = 1;
1239 c->default_value = 48;
1240 c->flags = 0;
1241 break;
1242 case V4L2_CID_SHARPNESS:
1243 c->type = V4L2_CTRL_TYPE_INTEGER;
1244 strcpy(c->name, "Sharpness");
1245 c->minimum = 0;
1246 c->maximum = 63;
1247 c->step = 1;
1248 c->default_value = 32;
1249 c->flags = 0;
1250 break;
1251 case V4L2_CID_PICTURE:
1252 c->type = V4L2_CTRL_TYPE_INTEGER;
1253 strcpy(c->name, "Picture");
1254 c->minimum = 0;
1255 c->maximum = 63;
1256 c->step = 1;
1257 c->default_value = 0;
1258 c->flags = 0;
1259 break;
1260 case V4L2_CID_JPEGQUAL:
1261 c->type = V4L2_CTRL_TYPE_INTEGER;
1262 strcpy(c->name, "JPEG quality");
1263 c->minimum = 0;
1264 c->maximum = 10;
1265 c->step = 1;
1266 c->default_value = 8;
1267 c->flags = 0;
1268 break;
1269 case V4L2_CID_FRAMERATE:
1270 c->type = V4L2_CTRL_TYPE_INTEGER;
1271 strcpy(c->name, "Framerate");
1272 c->minimum = 0;
1273 c->maximum = 31;
1274 c->step = 1;
1275 c->default_value = 0;
1276 c->flags = 0;
1277 break;
1278 default:
1279 return -EINVAL;
1280 }
1281 break;
1282 } 1281 }
1283 1282
1284 case VIDIOC_S_CTRL: { 1283 return 0;
1285 struct v4l2_control *c = arg; 1284}
1286 1285
1287 mutex_lock(&meye.lock); 1286static int vidioc_try_fmt_cap(struct file *file, void *fh,
1288 switch (c->id) { 1287 struct v4l2_format *f)
1289 case V4L2_CID_BRIGHTNESS: 1288{
1290 sony_pic_camera_command( 1289 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1291 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value); 1290 return -EINVAL;
1292 meye.picture.brightness = c->value << 10; 1291
1293 break; 1292 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1294 case V4L2_CID_HUE: 1293 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1295 sony_pic_camera_command( 1294 return -EINVAL;
1296 SONY_PIC_COMMAND_SETCAMERAHUE, c->value); 1295
1297 meye.picture.hue = c->value << 10; 1296 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1298 break; 1297 f->fmt.pix.field != V4L2_FIELD_NONE)
1299 case V4L2_CID_CONTRAST: 1298 return -EINVAL;
1300 sony_pic_camera_command( 1299
1301 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value); 1300 f->fmt.pix.field = V4L2_FIELD_NONE;
1302 meye.picture.contrast = c->value << 10; 1301
1303 break; 1302 if (f->fmt.pix.width <= 320) {
1304 case V4L2_CID_SATURATION: 1303 f->fmt.pix.width = 320;
1305 sony_pic_camera_command( 1304 f->fmt.pix.height = 240;
1306 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value); 1305 } else {
1307 meye.picture.colour = c->value << 10; 1306 f->fmt.pix.width = 640;
1308 break; 1307 f->fmt.pix.height = 480;
1309 case V4L2_CID_AGC:
1310 sony_pic_camera_command(
1311 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1312 meye.params.agc = c->value;
1313 break;
1314 case V4L2_CID_SHARPNESS:
1315 sony_pic_camera_command(
1316 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1317 meye.params.sharpness = c->value;
1318 break;
1319 case V4L2_CID_PICTURE:
1320 sony_pic_camera_command(
1321 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1322 meye.params.picture = c->value;
1323 break;
1324 case V4L2_CID_JPEGQUAL:
1325 meye.params.quality = c->value;
1326 break;
1327 case V4L2_CID_FRAMERATE:
1328 meye.params.framerate = c->value;
1329 break;
1330 default:
1331 mutex_unlock(&meye.lock);
1332 return -EINVAL;
1333 }
1334 mutex_unlock(&meye.lock);
1335 break;
1336 } 1308 }
1337 1309
1338 case VIDIOC_G_CTRL: { 1310 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1339 struct v4l2_control *c = arg; 1311 f->fmt.pix.sizeimage = f->fmt.pix.height *
1312 f->fmt.pix.bytesperline;
1313 f->fmt.pix.colorspace = 0;
1314 f->fmt.pix.priv = 0;
1340 1315
1341 mutex_lock(&meye.lock); 1316 return 0;
1342 switch (c->id) { 1317}
1343 case V4L2_CID_BRIGHTNESS: 1318
1344 c->value = meye.picture.brightness >> 10; 1319static int vidioc_g_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
1345 break; 1320{
1346 case V4L2_CID_HUE: 1321 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1347 c->value = meye.picture.hue >> 10; 1322 return -EINVAL;
1348 break; 1323
1349 case V4L2_CID_CONTRAST: 1324 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
1350 c->value = meye.picture.contrast >> 10; 1325 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1351 break; 1326
1352 case V4L2_CID_SATURATION: 1327 switch (meye.mchip_mode) {
1353 c->value = meye.picture.colour >> 10; 1328 case MCHIP_HIC_MODE_CONT_OUT:
1354 break; 1329 default:
1355 case V4L2_CID_AGC: 1330 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1356 c->value = meye.params.agc; 1331 break;
1357 break; 1332 case MCHIP_HIC_MODE_CONT_COMP:
1358 case V4L2_CID_SHARPNESS: 1333 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
1359 c->value = meye.params.sharpness;
1360 break;
1361 case V4L2_CID_PICTURE:
1362 c->value = meye.params.picture;
1363 break;
1364 case V4L2_CID_JPEGQUAL:
1365 c->value = meye.params.quality;
1366 break;
1367 case V4L2_CID_FRAMERATE:
1368 c->value = meye.params.framerate;
1369 break;
1370 default:
1371 mutex_unlock(&meye.lock);
1372 return -EINVAL;
1373 }
1374 mutex_unlock(&meye.lock);
1375 break; 1334 break;
1376 } 1335 }
1377 1336
1378 case VIDIOC_ENUM_FMT: { 1337 f->fmt.pix.field = V4L2_FIELD_NONE;
1379 struct v4l2_fmtdesc *f = arg; 1338 f->fmt.pix.width = mchip_hsize();
1380 1339 f->fmt.pix.height = mchip_vsize();
1381 if (f->index > 1) 1340 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1382 return -EINVAL; 1341 f->fmt.pix.sizeimage = f->fmt.pix.height *
1383 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1342 f->fmt.pix.bytesperline;
1384 return -EINVAL; 1343 f->fmt.pix.colorspace = 0;
1385 if (f->index == 0) { 1344 f->fmt.pix.priv = 0;
1386 /* standard YUV 422 capture */ 1345
1387 memset(f, 0, sizeof(*f)); 1346 return 0;
1388 f->index = 0; 1347}
1389 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1348
1390 f->flags = 0; 1349static int vidioc_s_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
1391 strcpy(f->description, "YUV422"); 1350{
1392 f->pixelformat = V4L2_PIX_FMT_YUYV; 1351 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1393 } else { 1352 return -EINVAL;
1394 /* compressed MJPEG capture */ 1353
1395 memset(f, 0, sizeof(*f)); 1354 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1396 f->index = 1; 1355 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1397 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1356 return -EINVAL;
1398 f->flags = V4L2_FMT_FLAG_COMPRESSED; 1357
1399 strcpy(f->description, "MJPEG"); 1358 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1400 f->pixelformat = V4L2_PIX_FMT_MJPEG; 1359 f->fmt.pix.field != V4L2_FIELD_NONE)
1401 } 1360 return -EINVAL;
1402 break; 1361
1362 f->fmt.pix.field = V4L2_FIELD_NONE;
1363 mutex_lock(&meye.lock);
1364
1365 if (f->fmt.pix.width <= 320) {
1366 f->fmt.pix.width = 320;
1367 f->fmt.pix.height = 240;
1368 meye.params.subsample = 1;
1369 } else {
1370 f->fmt.pix.width = 640;
1371 f->fmt.pix.height = 480;
1372 meye.params.subsample = 0;
1403 } 1373 }
1404 1374
1405 case VIDIOC_TRY_FMT: { 1375 switch (f->fmt.pix.pixelformat) {
1406 struct v4l2_format *f = arg; 1376 case V4L2_PIX_FMT_YUYV:
1407 1377 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
1408 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1378 break;
1409 return -EINVAL; 1379 case V4L2_PIX_FMT_MJPEG:
1410 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV && 1380 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1411 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1412 return -EINVAL;
1413 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1414 f->fmt.pix.field != V4L2_FIELD_NONE)
1415 return -EINVAL;
1416 f->fmt.pix.field = V4L2_FIELD_NONE;
1417 if (f->fmt.pix.width <= 320) {
1418 f->fmt.pix.width = 320;
1419 f->fmt.pix.height = 240;
1420 } else {
1421 f->fmt.pix.width = 640;
1422 f->fmt.pix.height = 480;
1423 }
1424 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1425 f->fmt.pix.sizeimage = f->fmt.pix.height *
1426 f->fmt.pix.bytesperline;
1427 f->fmt.pix.colorspace = 0;
1428 f->fmt.pix.priv = 0;
1429 break; 1381 break;
1430 } 1382 }
1431 1383
1432 case VIDIOC_G_FMT: { 1384 mutex_unlock(&meye.lock);
1433 struct v4l2_format *f = arg; 1385 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1386 f->fmt.pix.sizeimage = f->fmt.pix.height *
1387 f->fmt.pix.bytesperline;
1388 f->fmt.pix.colorspace = 0;
1389 f->fmt.pix.priv = 0;
1434 1390
1435 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1391 return 0;
1436 return -EINVAL; 1392}
1437 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
1438 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1439 switch (meye.mchip_mode) {
1440 case MCHIP_HIC_MODE_CONT_OUT:
1441 default:
1442 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1443 break;
1444 case MCHIP_HIC_MODE_CONT_COMP:
1445 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
1446 break;
1447 }
1448 f->fmt.pix.field = V4L2_FIELD_NONE;
1449 f->fmt.pix.width = mchip_hsize();
1450 f->fmt.pix.height = mchip_vsize();
1451 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1452 f->fmt.pix.sizeimage = f->fmt.pix.height *
1453 f->fmt.pix.bytesperline;
1454 f->fmt.pix.colorspace = 0;
1455 f->fmt.pix.priv = 0;
1456 break;
1457 }
1458 1393
1459 case VIDIOC_S_FMT: { 1394static int vidioc_reqbufs(struct file *file, void *fh,
1460 struct v4l2_format *f = arg; 1395 struct v4l2_requestbuffers *req)
1461 1396{
1462 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1397 int i;
1463 return -EINVAL;
1464 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1465 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1466 return -EINVAL;
1467 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1468 f->fmt.pix.field != V4L2_FIELD_NONE)
1469 return -EINVAL;
1470 f->fmt.pix.field = V4L2_FIELD_NONE;
1471 mutex_lock(&meye.lock);
1472 if (f->fmt.pix.width <= 320) {
1473 f->fmt.pix.width = 320;
1474 f->fmt.pix.height = 240;
1475 meye.params.subsample = 1;
1476 } else {
1477 f->fmt.pix.width = 640;
1478 f->fmt.pix.height = 480;
1479 meye.params.subsample = 0;
1480 }
1481 switch (f->fmt.pix.pixelformat) {
1482 case V4L2_PIX_FMT_YUYV:
1483 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
1484 break;
1485 case V4L2_PIX_FMT_MJPEG:
1486 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1487 break;
1488 }
1489 mutex_unlock(&meye.lock);
1490 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1491 f->fmt.pix.sizeimage = f->fmt.pix.height *
1492 f->fmt.pix.bytesperline;
1493 f->fmt.pix.colorspace = 0;
1494 f->fmt.pix.priv = 0;
1495 1398
1496 break; 1399 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1497 } 1400 return -EINVAL;
1498 1401
1499 case VIDIOC_REQBUFS: { 1402 if (req->memory != V4L2_MEMORY_MMAP)
1500 struct v4l2_requestbuffers *req = arg; 1403 return -EINVAL;
1501 int i;
1502 1404
1503 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1405 if (meye.grab_fbuffer && req->count == gbuffers) {
1504 return -EINVAL; 1406 /* already allocated, no modifications */
1505 if (req->memory != V4L2_MEMORY_MMAP) 1407 return 0;
1506 return -EINVAL;
1507 if (meye.grab_fbuffer && req->count == gbuffers) {
1508 /* already allocated, no modifications */
1509 break;
1510 }
1511 mutex_lock(&meye.lock);
1512 if (meye.grab_fbuffer) {
1513 for (i = 0; i < gbuffers; i++)
1514 if (meye.vma_use_count[i]) {
1515 mutex_unlock(&meye.lock);
1516 return -EINVAL;
1517 }
1518 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
1519 meye.grab_fbuffer = NULL;
1520 }
1521 gbuffers = max(2, min((int)req->count, MEYE_MAX_BUFNBRS));
1522 req->count = gbuffers;
1523 meye.grab_fbuffer = rvmalloc(gbuffers * gbufsize);
1524 if (!meye.grab_fbuffer) {
1525 printk(KERN_ERR "meye: v4l framebuffer allocation"
1526 " failed\n");
1527 mutex_unlock(&meye.lock);
1528 return -ENOMEM;
1529 }
1530 for (i = 0; i < gbuffers; i++)
1531 meye.vma_use_count[i] = 0;
1532 mutex_unlock(&meye.lock);
1533 break;
1534 } 1408 }
1535 1409
1536 case VIDIOC_QUERYBUF: { 1410 mutex_lock(&meye.lock);
1537 struct v4l2_buffer *buf = arg; 1411 if (meye.grab_fbuffer) {
1538 int index = buf->index; 1412 for (i = 0; i < gbuffers; i++)
1539 1413 if (meye.vma_use_count[i]) {
1540 if (index < 0 || index >= gbuffers) 1414 mutex_unlock(&meye.lock);
1541 return -EINVAL; 1415 return -EINVAL;
1542 memset(buf, 0, sizeof(*buf)); 1416 }
1543 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1417 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
1544 buf->index = index; 1418 meye.grab_fbuffer = NULL;
1545 buf->bytesused = meye.grab_buffer[index].size;
1546 buf->flags = V4L2_BUF_FLAG_MAPPED;
1547 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1548 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1549 if (meye.grab_buffer[index].state == MEYE_BUF_DONE)
1550 buf->flags |= V4L2_BUF_FLAG_DONE;
1551 buf->field = V4L2_FIELD_NONE;
1552 buf->timestamp = meye.grab_buffer[index].timestamp;
1553 buf->sequence = meye.grab_buffer[index].sequence;
1554 buf->memory = V4L2_MEMORY_MMAP;
1555 buf->m.offset = index * gbufsize;
1556 buf->length = gbufsize;
1557 break;
1558 } 1419 }
1559 1420
1560 case VIDIOC_QBUF: { 1421 gbuffers = max(2, min((int)req->count, MEYE_MAX_BUFNBRS));
1561 struct v4l2_buffer *buf = arg; 1422 req->count = gbuffers;
1562 1423 meye.grab_fbuffer = rvmalloc(gbuffers * gbufsize);
1563 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1424
1564 return -EINVAL; 1425 if (!meye.grab_fbuffer) {
1565 if (buf->memory != V4L2_MEMORY_MMAP) 1426 printk(KERN_ERR "meye: v4l framebuffer allocation"
1566 return -EINVAL; 1427 " failed\n");
1567 if (buf->index < 0 || buf->index >= gbuffers)
1568 return -EINVAL;
1569 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1570 return -EINVAL;
1571 mutex_lock(&meye.lock);
1572 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1573 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1574 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1575 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1576 mutex_unlock(&meye.lock); 1428 mutex_unlock(&meye.lock);
1577 break; 1429 return -ENOMEM;
1578 } 1430 }
1579 1431
1580 case VIDIOC_DQBUF: { 1432 for (i = 0; i < gbuffers; i++)
1581 struct v4l2_buffer *buf = arg; 1433 meye.vma_use_count[i] = 0;
1582 int reqnr;
1583 1434
1584 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1435 mutex_unlock(&meye.lock);
1585 return -EINVAL;
1586 if (buf->memory != V4L2_MEMORY_MMAP)
1587 return -EINVAL;
1588 1436
1589 mutex_lock(&meye.lock); 1437 return 0;
1590 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) { 1438}
1591 mutex_unlock(&meye.lock); 1439
1592 return -EAGAIN; 1440static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1593 } 1441{
1594 if (wait_event_interruptible(meye.proc_list, 1442 int index = buf->index;
1595 kfifo_len(meye.doneq) != 0) < 0) { 1443
1596 mutex_unlock(&meye.lock); 1444 if (index < 0 || index >= gbuffers)
1597 return -EINTR; 1445 return -EINVAL;
1598 } 1446
1599 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr, 1447 memset(buf, 0, sizeof(*buf));
1600 sizeof(int))) { 1448
1601 mutex_unlock(&meye.lock); 1449 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1602 return -EBUSY; 1450 buf->index = index;
1603 } 1451 buf->bytesused = meye.grab_buffer[index].size;
1604 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) { 1452 buf->flags = V4L2_BUF_FLAG_MAPPED;
1605 mutex_unlock(&meye.lock); 1453
1606 return -EINVAL; 1454 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1607 } 1455 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1608 buf->index = reqnr; 1456
1609 buf->bytesused = meye.grab_buffer[reqnr].size; 1457 if (meye.grab_buffer[index].state == MEYE_BUF_DONE)
1610 buf->flags = V4L2_BUF_FLAG_MAPPED; 1458 buf->flags |= V4L2_BUF_FLAG_DONE;
1611 buf->field = V4L2_FIELD_NONE; 1459
1612 buf->timestamp = meye.grab_buffer[reqnr].timestamp; 1460 buf->field = V4L2_FIELD_NONE;
1613 buf->sequence = meye.grab_buffer[reqnr].sequence; 1461 buf->timestamp = meye.grab_buffer[index].timestamp;
1614 buf->memory = V4L2_MEMORY_MMAP; 1462 buf->sequence = meye.grab_buffer[index].sequence;
1615 buf->m.offset = reqnr * gbufsize; 1463 buf->memory = V4L2_MEMORY_MMAP;
1616 buf->length = gbufsize; 1464 buf->m.offset = index * gbufsize;
1617 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED; 1465 buf->length = gbufsize;
1466
1467 return 0;
1468}
1469
1470static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1471{
1472 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1473 return -EINVAL;
1474
1475 if (buf->memory != V4L2_MEMORY_MMAP)
1476 return -EINVAL;
1477
1478 if (buf->index < 0 || buf->index >= gbuffers)
1479 return -EINVAL;
1480
1481 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1482 return -EINVAL;
1483
1484 mutex_lock(&meye.lock);
1485 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1486 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1487 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1488 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1489 mutex_unlock(&meye.lock);
1490
1491 return 0;
1492}
1493
1494static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1495{
1496 int reqnr;
1497
1498 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1499 return -EINVAL;
1500
1501 if (buf->memory != V4L2_MEMORY_MMAP)
1502 return -EINVAL;
1503
1504 mutex_lock(&meye.lock);
1505
1506 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
1618 mutex_unlock(&meye.lock); 1507 mutex_unlock(&meye.lock);
1619 break; 1508 return -EAGAIN;
1620 } 1509 }
1621 1510
1622 case VIDIOC_STREAMON: { 1511 if (wait_event_interruptible(meye.proc_list,
1623 mutex_lock(&meye.lock); 1512 kfifo_len(meye.doneq) != 0) < 0) {
1624 switch (meye.mchip_mode) {
1625 case MCHIP_HIC_MODE_CONT_OUT:
1626 mchip_continuous_start();
1627 break;
1628 case MCHIP_HIC_MODE_CONT_COMP:
1629 mchip_cont_compression_start();
1630 break;
1631 default:
1632 mutex_unlock(&meye.lock);
1633 return -EINVAL;
1634 }
1635 mutex_unlock(&meye.lock); 1513 mutex_unlock(&meye.lock);
1636 break; 1514 return -EINTR;
1637 } 1515 }
1638 1516
1639 case VIDIOC_STREAMOFF: { 1517 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr,
1640 int i; 1518 sizeof(int))) {
1519 mutex_unlock(&meye.lock);
1520 return -EBUSY;
1521 }
1641 1522
1642 mutex_lock(&meye.lock); 1523 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) {
1643 mchip_hic_stop();
1644 kfifo_reset(meye.grabq);
1645 kfifo_reset(meye.doneq);
1646 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1647 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1648 mutex_unlock(&meye.lock); 1524 mutex_unlock(&meye.lock);
1649 break; 1525 return -EINVAL;
1650 } 1526 }
1651 1527
1652 /* 1528 buf->index = reqnr;
1653 * XXX what about private snapshot ioctls ? 1529 buf->bytesused = meye.grab_buffer[reqnr].size;
1654 * Do they need to be converted to V4L2 ? 1530 buf->flags = V4L2_BUF_FLAG_MAPPED;
1655 */ 1531 buf->field = V4L2_FIELD_NONE;
1532 buf->timestamp = meye.grab_buffer[reqnr].timestamp;
1533 buf->sequence = meye.grab_buffer[reqnr].sequence;
1534 buf->memory = V4L2_MEMORY_MMAP;
1535 buf->m.offset = reqnr * gbufsize;
1536 buf->length = gbufsize;
1537 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED;
1538 mutex_unlock(&meye.lock);
1539
1540 return 0;
1541}
1656 1542
1543static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
1544{
1545 mutex_lock(&meye.lock);
1546
1547 switch (meye.mchip_mode) {
1548 case MCHIP_HIC_MODE_CONT_OUT:
1549 mchip_continuous_start();
1550 break;
1551 case MCHIP_HIC_MODE_CONT_COMP:
1552 mchip_cont_compression_start();
1553 break;
1657 default: 1554 default:
1658 return -ENOIOCTLCMD; 1555 mutex_unlock(&meye.lock);
1556 return -EINVAL;
1659 } 1557 }
1660 1558
1559 mutex_unlock(&meye.lock);
1560
1661 return 0; 1561 return 0;
1662} 1562}
1663 1563
1664static int meye_ioctl(struct inode *inode, struct file *file, 1564static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
1665 unsigned int cmd, unsigned long arg)
1666{ 1565{
1667 return video_usercopy(inode, file, cmd, arg, meye_do_ioctl); 1566 mutex_lock(&meye.lock);
1567 mchip_hic_stop();
1568 kfifo_reset(meye.grabq);
1569 kfifo_reset(meye.doneq);
1570
1571 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1572 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1573
1574 mutex_unlock(&meye.lock);
1575 return 0;
1576}
1577
1578static int vidioc_default(struct file *file, void *fh, int cmd, void *arg)
1579{
1580 switch (cmd) {
1581 case MEYEIOC_G_PARAMS:
1582 return meyeioc_g_params((struct meye_params *) arg);
1583
1584 case MEYEIOC_S_PARAMS:
1585 return meyeioc_s_params((struct meye_params *) arg);
1586
1587 case MEYEIOC_QBUF_CAPT:
1588 return meyeioc_qbuf_capt((int *) arg);
1589
1590 case MEYEIOC_SYNC:
1591 return meyeioc_sync(file, fh, (int *) arg);
1592
1593 case MEYEIOC_STILLCAPT:
1594 return meyeioc_stillcapt();
1595
1596 case MEYEIOC_STILLJCAPT:
1597 return meyeioc_stilljcapt((int *) arg);
1598
1599 default:
1600 return -EINVAL;
1601 }
1602
1668} 1603}
1669 1604
1670static unsigned int meye_poll(struct file *file, poll_table *wait) 1605static unsigned int meye_poll(struct file *file, poll_table *wait)
@@ -1752,8 +1687,10 @@ static const struct file_operations meye_fops = {
1752 .open = meye_open, 1687 .open = meye_open,
1753 .release = meye_release, 1688 .release = meye_release,
1754 .mmap = meye_mmap, 1689 .mmap = meye_mmap,
1755 .ioctl = meye_ioctl, 1690 .ioctl = video_ioctl2,
1691#ifdef CONFIG_COMPAT
1756 .compat_ioctl = v4l_compat_ioctl32, 1692 .compat_ioctl = v4l_compat_ioctl32,
1693#endif
1757 .poll = meye_poll, 1694 .poll = meye_poll,
1758 .llseek = no_llseek, 1695 .llseek = no_llseek,
1759}; 1696};
@@ -1765,6 +1702,24 @@ static struct video_device meye_template = {
1765 .fops = &meye_fops, 1702 .fops = &meye_fops,
1766 .release = video_device_release, 1703 .release = video_device_release,
1767 .minor = -1, 1704 .minor = -1,
1705 .vidioc_querycap = vidioc_querycap,
1706 .vidioc_enum_input = vidioc_enum_input,
1707 .vidioc_g_input = vidioc_g_input,
1708 .vidioc_s_input = vidioc_s_input,
1709 .vidioc_queryctrl = vidioc_queryctrl,
1710 .vidioc_s_ctrl = vidioc_s_ctrl,
1711 .vidioc_g_ctrl = vidioc_g_ctrl,
1712 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1713 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1714 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1715 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1716 .vidioc_reqbufs = vidioc_reqbufs,
1717 .vidioc_querybuf = vidioc_querybuf,
1718 .vidioc_qbuf = vidioc_qbuf,
1719 .vidioc_dqbuf = vidioc_dqbuf,
1720 .vidioc_streamon = vidioc_streamon,
1721 .vidioc_streamoff = vidioc_streamoff,
1722 .vidioc_default = vidioc_default,
1768}; 1723};
1769 1724
1770#ifdef CONFIG_PM 1725#ifdef CONFIG_PM