V4L/DVB (11327): ov772x: add edge contrl support
[safe/jmp/linux-2.6] / drivers / media / video / pvrusb2 / pvrusb2-v4l2.c
index bd6169f..9e0f2b0 100644 (file)
@@ -91,7 +91,7 @@ static struct v4l2_capability pvr_capability ={
        .card           = "Hauppauge WinTV pvr-usb2",
        .bus_info       = "usb",
        .version        = KERNEL_VERSION(0,8,0),
-       .capabilities   = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
+       .capabilities   = (V4L2_CAP_VIDEO_CAPTURE |
                           V4L2_CAP_TUNER | V4L2_CAP_AUDIO | V4L2_CAP_RADIO |
                           V4L2_CAP_READWRITE),
        .reserved       = {0,0,0,0}
@@ -168,14 +168,13 @@ static const char *get_v4l_name(int v4l_type)
  * This is part of Video 4 Linux API. The procedure handles ioctl() calls.
  *
  */
-static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
-                             unsigned int cmd, void *arg)
+static long pvr2_v4l2_do_ioctl(struct file *file, unsigned int cmd, void *arg)
 {
        struct pvr2_v4l2_fh *fh = file->private_data;
        struct pvr2_v4l2 *vp = fh->vhead;
        struct pvr2_v4l2_dev *dev_info = fh->dev_info;
        struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
-       int ret = -EINVAL;
+       long ret = -EINVAL;
 
        if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
                v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),cmd);
@@ -533,7 +532,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
 
                        lmin = pvr2_ctrl_get_min(hcp);
                        lmax = pvr2_ctrl_get_max(hcp);
-                       ldef = pvr2_ctrl_get_def(hcp);
+                       pvr2_ctrl_get_def(hcp, &ldef);
                        if (w == -1) {
                                w = ldef;
                        } else if (w < lmin) {
@@ -543,7 +542,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                        }
                        lmin = pvr2_ctrl_get_min(vcp);
                        lmax = pvr2_ctrl_get_max(vcp);
-                       ldef = pvr2_ctrl_get_def(vcp);
+                       pvr2_ctrl_get_def(vcp, &ldef);
                        if (h == -1) {
                                h = ldef;
                        } else if (h < lmin) {
@@ -604,6 +603,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_QUERYCTRL:
        {
                struct pvr2_ctrl *cptr;
+               int val;
                struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
                ret = 0;
                if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
@@ -627,7 +627,8 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                           pvr2_ctrl_get_desc(cptr));
                strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
                vc->flags = pvr2_ctrl_get_v4lflags(cptr);
-               vc->default_value = pvr2_ctrl_get_def(cptr);
+               pvr2_ctrl_get_def(cptr, &val);
+               vc->default_value = val;
                switch (pvr2_ctrl_get_type(cptr)) {
                case pvr2_ctl_enum:
                        vc->type = V4L2_CTRL_TYPE_MENU;
@@ -753,6 +754,92 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                break;
        }
 
+       case VIDIOC_CROPCAP:
+       {
+               struct v4l2_cropcap *cap = (struct v4l2_cropcap *)arg;
+               if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_hdw_get_cropcap(hdw, cap);
+               cap->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* paranoia */
+               break;
+       }
+       case VIDIOC_G_CROP:
+       {
+               struct v4l2_crop *crop = (struct v4l2_crop *)arg;
+               int val = 0;
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.left = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.top = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.width = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.height = val;
+       }
+       case VIDIOC_S_CROP:
+       {
+               struct v4l2_crop *crop = (struct v4l2_crop *)arg;
+               struct v4l2_cropcap cap;
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL),
+                       crop->c.left);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT),
+                       crop->c.top);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW),
+                       crop->c.width);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH),
+                       crop->c.height);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+       }
        case VIDIOC_LOG_STATUS:
        {
                pvr2_hdw_trigger_module_log(hdw);
@@ -764,19 +851,19 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_DBG_G_REGISTER:
        {
                u64 val;
-               struct v4l2_register *req = (struct v4l2_register *)arg;
+               struct v4l2_dbg_register *req = (struct v4l2_dbg_register *)arg;
                if (cmd == VIDIOC_DBG_S_REGISTER) val = req->val;
                ret = pvr2_hdw_register_access(
-                       hdw,req->match_type,req->match_chip,req->reg,
-                       cmd == VIDIOC_DBG_S_REGISTER,&val);
+                       hdw, &req->match, req->reg,
+                       cmd == VIDIOC_DBG_S_REGISTER, &val);
                if (cmd == VIDIOC_DBG_G_REGISTER) req->val = val;
                break;
        }
 #endif
 
        default :
-               ret = v4l_compat_translate_ioctl(inode,file,cmd,
-                                                arg,pvr2_v4l2_do_ioctl);
+               ret = v4l_compat_translate_ioctl(file, cmd,
+                                                arg, pvr2_v4l2_do_ioctl);
        }
 
        pvr2_hdw_commit_ctl(hdw);
@@ -784,28 +871,27 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
        if (ret < 0) {
                if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
                        pvr2_trace(PVR2_TRACE_V4LIOCTL,
-                                  "pvr2_v4l2_do_ioctl failure, ret=%d",ret);
+                                  "pvr2_v4l2_do_ioctl failure, ret=%ld", ret);
                } else {
                        if (pvrusb2_debug & PVR2_TRACE_V4LIOCTL) {
                                pvr2_trace(PVR2_TRACE_V4LIOCTL,
-                                          "pvr2_v4l2_do_ioctl failure, ret=%d"
-                                          " command was:",ret);
+                                          "pvr2_v4l2_do_ioctl failure, ret=%ld"
+                                          " command was:", ret);
                                v4l_print_ioctl(pvr2_hdw_get_driver_name(hdw),
                                                cmd);
                        }
                }
        } else {
                pvr2_trace(PVR2_TRACE_V4LIOCTL,
-                          "pvr2_v4l2_do_ioctl complete, ret=%d (0x%x)",
-                          ret,ret);
+                          "pvr2_v4l2_do_ioctl complete, ret=%ld (0x%lx)",
+                          ret, ret);
        }
        return ret;
 }
 
-
 static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
 {
-       int minor_id = dip->devbase.minor;
+       int num = dip->devbase.num;
        struct pvr2_hdw *hdw = dip->v4lp->channel.mc_head->hdw;
        enum pvr2_config cfg = dip->config;
        int v4l_type = dip->v4l_type;
@@ -821,7 +907,7 @@ static void pvr2_v4l2_dev_destroy(struct pvr2_v4l2_dev *dip)
        video_unregister_device(&dip->devbase);
 
        printk(KERN_INFO "pvrusb2: unregistered device %s%u [%s]\n",
-              get_v4l_name(v4l_type),minor_id & 0x1f,
+              get_v4l_name(v4l_type), num,
               pvr2_config_get_name(cfg));
 
 }
@@ -862,19 +948,15 @@ static void pvr2_v4l2_internal_check(struct pvr2_channel *chp)
 }
 
 
-static int pvr2_v4l2_ioctl(struct inode *inode, struct file *file,
+static long pvr2_v4l2_ioctl(struct file *file,
                           unsigned int cmd, unsigned long arg)
 {
 
-/* Temporary hack : use ivtv api until a v4l2 one is available. */
-#define IVTV_IOC_G_CODEC        0xFFEE7703
-#define IVTV_IOC_S_CODEC        0xFFEE7704
-       if (cmd == IVTV_IOC_G_CODEC || cmd == IVTV_IOC_S_CODEC) return 0;
-       return video_usercopy(inode, file, cmd, arg, pvr2_v4l2_do_ioctl);
+       return video_usercopy(file, cmd, arg, pvr2_v4l2_do_ioctl);
 }
 
 
-static int pvr2_v4l2_release(struct inode *inode, struct file *file)
+static int pvr2_v4l2_release(struct file *file)
 {
        struct pvr2_v4l2_fh *fhp = file->private_data;
        struct pvr2_v4l2 *vp = fhp->vhead;
@@ -922,7 +1004,7 @@ static int pvr2_v4l2_release(struct inode *inode, struct file *file)
 }
 
 
-static int pvr2_v4l2_open(struct inode *inode, struct file *file)
+static int pvr2_v4l2_open(struct file *file)
 {
        struct pvr2_v4l2_dev *dip; /* Our own context pointer */
        struct pvr2_v4l2_fh *fhp;
@@ -1149,23 +1231,17 @@ static unsigned int pvr2_v4l2_poll(struct file *file, poll_table *wait)
 }
 
 
-static const struct file_operations vdev_fops = {
+static const struct v4l2_file_operations vdev_fops = {
        .owner      = THIS_MODULE,
        .open       = pvr2_v4l2_open,
        .release    = pvr2_v4l2_release,
        .read       = pvr2_v4l2_read,
        .ioctl      = pvr2_v4l2_ioctl,
-       .llseek     = no_llseek,
        .poll       = pvr2_v4l2_poll,
 };
 
 
 static struct video_device vdev_template = {
-       .owner      = THIS_MODULE,
-       .type       = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
-       .type2      = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
-                      | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
-                      | V4L2_CAP_READWRITE),
        .fops       = &vdev_fops,
 };
 
@@ -1188,8 +1264,9 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
                dip->minor_type = pvr2_v4l_type_video;
                nr_ptr = video_nr;
                if (!dip->stream) {
-                       err("Failed to set up pvrusb2 v4l video dev"
-                           " due to missing stream instance");
+                       pr_err(KBUILD_MODNAME
+                               ": Failed to set up pvrusb2 v4l video dev"
+                               " due to missing stream instance\n");
                        return;
                }
                break;
@@ -1206,8 +1283,8 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
                break;
        default:
                /* Bail out (this should be impossible) */
-               err("Failed to set up pvrusb2 v4l dev"
-                   " due to unrecognized config");
+               pr_err(KBUILD_MODNAME ": Failed to set up pvrusb2 v4l dev"
+                   " due to unrecognized config\n");
                return;
        }
 
@@ -1223,11 +1300,12 @@ static void pvr2_v4l2_dev_init(struct pvr2_v4l2_dev *dip,
                                   dip->v4l_type, mindevnum) < 0) &&
            (video_register_device(&dip->devbase,
                                   dip->v4l_type, -1) < 0)) {
-               err("Failed to register pvrusb2 v4l device");
+               pr_err(KBUILD_MODNAME
+                       ": Failed to register pvrusb2 v4l device\n");
        }
 
        printk(KERN_INFO "pvrusb2: registered device %s%u [%s]\n",
-              get_v4l_name(dip->v4l_type),dip->devbase.minor & 0x1f,
+              get_v4l_name(dip->v4l_type), dip->devbase.num,
               pvr2_config_get_name(dip->config));
 
        pvr2_hdw_v4l_store_minor_number(vp->channel.mc_head->hdw,