Merge branch 'drm-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied...
[safe/jmp/linux-2.6] / drivers / media / video / ov511.c
index da44579..d55d580 100644 (file)
@@ -15,7 +15,7 @@
  *
  * Based on the Linux CPiA driver written by Peter Pregler,
  * Scott J. Bertin and Johannes Erdfelt.
- * 
+ *
  * Please see the file: Documentation/usb/ov511.txt
  * and the website at:  http://alpha.dyndns.org/ov511
  * for more info.
@@ -35,7 +35,6 @@
  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/vmalloc.h>
@@ -182,7 +181,7 @@ module_param(force_palette, int, 0);
 MODULE_PARM_DESC(force_palette, "Force the palette to a specific value");
 module_param(backlight, int, 0);
 MODULE_PARM_DESC(backlight, "For objects that are lit from behind");
-static int num_uv;
+static unsigned int num_uv;
 module_param_array(unit_video, int, &num_uv, 0);
 MODULE_PARM_DESC(unit_video,
   "Force use of specific minor number(s). 0 is not allowed.");
@@ -302,10 +301,11 @@ static struct symbolic_list senlist[] = {
 static struct symbolic_list urb_errlist[] = {
        { -ENOSR,       "Buffer error (overrun)" },
        { -EPIPE,       "Stalled (device not responding)" },
-       { -EOVERFLOW,   "Babble (bad cable?)" },
+       { -EOVERFLOW,   "Babble (device sends too much data)" },
        { -EPROTO,      "Bit-stuff error (bad cable?)" },
-       { -EILSEQ,      "CRC/Timeout" },
-       { -ETIMEDOUT,   "NAK (device does not respond)" },
+       { -EILSEQ,      "CRC/Timeout (bad cable?)" },
+       { -ETIME,       "Device does not respond to token" },
+       { -ETIMEDOUT,   "Device does not respond to command" },
        { -1, NULL }
 };
 
@@ -433,7 +433,7 @@ reg_w_mask(struct usb_ov511 *ov,
        return (reg_w(ov, reg, newval));
 }
 
-/* 
+/*
  * Writes multiple (n) byte value to a single register. Only valid with certain
  * registers (0x30 and 0xc4 - 0xce).
  */
@@ -629,7 +629,7 @@ ov511_i2c_write_internal(struct usb_ov511 *ov,
                /* Retry until idle */
                do
                        rc = reg_r(ov, R511_I2C_CTL);
-               while (rc > 0 && ((rc&1) == 0)); 
+               while (rc > 0 && ((rc&1) == 0));
                if (rc < 0)
                        break;
 
@@ -1752,7 +1752,7 @@ sensor_set_picture(struct usb_ov511 *ov, struct video_picture *p)
        ov->whiteness = p->whiteness;
 
        /* Don't return error if a setting is unsupported, or rest of settings
-         * will not be performed */
+        * will not be performed */
 
        rc = sensor_set_contrast(ov, p->contrast);
        if (FATAL_ERROR(rc))
@@ -1781,7 +1781,7 @@ sensor_get_picture(struct usb_ov511 *ov, struct video_picture *p)
        PDEBUG(4, "sensor_get_picture");
 
        /* Don't return error if a setting is unsupported, or rest of settings
-         * will not be performed */
+        * will not be performed */
 
        rc = sensor_get_contrast(ov, &(p->contrast));
        if (FATAL_ERROR(rc))
@@ -2251,7 +2251,7 @@ mode_init_ov_sensor_regs(struct usb_ov511 *ov, int width, int height,
 
        /******** Clock programming ********/
 
-       /* The OV6620 needs special handling. This prevents the 
+       /* The OV6620 needs special handling. This prevents the
         * severe banding that normally occurs */
        if (ov->sensor == SEN_OV6620 || ov->sensor == SEN_OV6630)
        {
@@ -2326,7 +2326,7 @@ set_ov_sensor_window(struct usb_ov511 *ov, int width, int height, int mode,
                     int sub_flag)
 {
        int ret;
-       int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize; 
+       int hwsbase, hwebase, vwsbase, vwebase, hwsize, vwsize;
        int hoffset, voffset, hwscale = 0, vwscale = 0;
 
        /* The different sensor ICs handle setting up of window differently.
@@ -2575,7 +2575,7 @@ ov518_mode_init_regs(struct usb_ov511 *ov,
                /* OV518 needs U and V swapped */
                i2c_w_mask(ov, 0x15, 0x00, 0x01);
 
-               if (mode == VIDEO_PALETTE_GREY) {
+               if (mode == VIDEO_PALETTE_GREY) {
                        /* Set 16-bit input format (UV data are ignored) */
                        reg_w_mask(ov, 0x20, 0x00, 0x08);
 
@@ -2894,7 +2894,7 @@ make_8x8(unsigned char *pIn, unsigned char *pOut, int w)
  *           ...              ...                    ...
  *     56 57 ... 63   120 121 ... 127        248 249 ... 255
  *
- */ 
+ */
 static void
 yuv400raw_to_yuv400p(struct ov511_frame *frame,
                     unsigned char *pIn0, unsigned char *pOut0)
@@ -2923,7 +2923,7 @@ yuv400raw_to_yuv400p(struct ov511_frame *frame,
  *
  *      0  1 ...  7
  *      8  9 ... 15
- *           ...   
+ *           ...
  *     56 57 ... 63
  *
  * U and V are shipped at half resolution (1 U,V sample -> one 2x2 block).
@@ -3034,7 +3034,7 @@ decompress(struct usb_ov511 *ov, struct ov511_frame *frame,
  */
 static void
 deinterlace(struct ov511_frame *frame, int rawformat,
-            unsigned char *pIn0, unsigned char *pOut0)
+           unsigned char *pIn0, unsigned char *pOut0)
 {
        const int fieldheight = frame->rawheight / 2;
        const int fieldpix = fieldheight * frame->rawwidth;
@@ -3112,7 +3112,7 @@ ov51x_postprocess_grey(struct usb_ov511 *ov, struct ov511_frame *frame)
                                                     frame->tempdata);
 
                        deinterlace(frame, RAWFMT_YUV400, frame->tempdata,
-                                   frame->data);
+                                   frame->data);
                } else {
                        if (frame->compressed)
                                decompress(ov, frame, frame->rawdata,
@@ -3136,7 +3136,7 @@ ov51x_postprocess_yuv420(struct usb_ov511 *ov, struct ov511_frame *frame)
                                             frame->tempdata);
 
                deinterlace(frame, RAWFMT_YUV420, frame->tempdata,
-                           frame->data);
+                           frame->data);
        } else {
                if (frame->compressed)
                        decompress(ov, frame, frame->rawdata, frame->data);
@@ -3226,7 +3226,7 @@ ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
                frame->rawwidth = ((int)(in[9]) + 1) * 8;
                frame->rawheight = ((int)(in[10]) + 1) * 8;
 
-               PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
+               PDEBUG(4, "Frame end, frame=%d, pnum=%d, w=%d, h=%d, recvd=%d",
                        ov->curframe, pnum, frame->rawwidth, frame->rawheight,
                        frame->bytes_recvd);
 
@@ -3239,7 +3239,7 @@ ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
                RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
 
                if (frame->scanstate == STATE_LINES) {
-                       int nextf;
+                       int nextf;
 
                        frame->grabstate = FRAME_DONE;
                        wake_up_interruptible(&frame->wq);
@@ -3405,7 +3405,7 @@ eof:
        RESTRICT_TO_RANGE(frame->bytes_recvd, 8, max_raw);
 
        if (frame->scanstate == STATE_LINES) {
-               int nextf;
+               int nextf;
 
                frame->grabstate = FRAME_DONE;
                wake_up_interruptible(&frame->wq);
@@ -3503,7 +3503,7 @@ check_middle:
 }
 
 static void
-ov51x_isoc_irq(struct urb *urb, struct pt_regs *regs)
+ov51x_isoc_irq(struct urb *urb)
 {
        int i;
        struct usb_ov511 *ov;
@@ -3527,10 +3527,10 @@ ov51x_isoc_irq(struct urb *urb, struct pt_regs *regs)
                return;
        }
 
-        if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
-                PDEBUG(4, "URB unlinked");
-                return;
-        }
+       if (urb->status == -ENOENT || urb->status == -ECONNRESET) {
+               PDEBUG(4, "URB unlinked");
+               return;
+       }
 
        if (urb->status != -EINPROGRESS && urb->status != 0) {
                err("ERROR: urb->status=%d: %s", urb->status,
@@ -4627,8 +4627,8 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
        PDEBUG(4, "mmap: %ld (%lX) bytes", size, size);
 
        if (size > (((OV511_NUMFRAMES
-                     * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
-                     + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
+                     * MAX_DATA_SIZE(ov->maxwidth, ov->maxheight)
+                     + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))))
                return -EINVAL;
 
        if (mutex_lock_interruptible(&ov->lock))
@@ -4653,7 +4653,7 @@ ov51x_v4l1_mmap(struct file *file, struct vm_area_struct *vma)
        return 0;
 }
 
-static struct file_operations ov511_fops = {
+static const struct file_operations ov511_fops = {
        .owner =        THIS_MODULE,
        .open =         ov51x_v4l1_open,
        .release =      ov51x_v4l1_close,
@@ -4668,7 +4668,6 @@ static struct video_device vdev_template = {
        .owner =        THIS_MODULE,
        .name =         "OV511 USB Camera",
        .type =         VID_TYPE_CAPTURE,
-       .hardware =     VID_HARDWARE_OV511,
        .fops =         &ov511_fops,
        .release =      video_device_release,
        .minor =        -1,
@@ -5062,7 +5061,7 @@ ov6xx0_configure(struct usb_ov511 *ov)
 }
 
 /* This initializes the KS0127 and KS0127B video decoders. */
-static int 
+static int
 ks0127_configure(struct usb_ov511 *ov)
 {
        int rc;
@@ -5193,7 +5192,7 @@ saa7111a_configure(struct usb_ov511 *ov)
                return -1;
 
        /* Detect version of decoder. This must be done after writing the
-         * initial regs or the decoder will lock up. */
+        * initial regs or the decoder will lock up. */
        rc = i2c_r(ov, 0x00);
 
        if (rc < 0) {
@@ -5216,13 +5215,13 @@ saa7111a_configure(struct usb_ov511 *ov)
 }
 
 /* This initializes the OV511/OV511+ and the sensor */
-static int 
+static int
 ov511_configure(struct usb_ov511 *ov)
 {
        static struct ov511_regvals aRegvalsInit511[] = {
                { OV511_REG_BUS, R51x_SYS_RESET,        0x7f },
-               { OV511_REG_BUS, R51x_SYS_INIT,         0x01 },
-               { OV511_REG_BUS, R51x_SYS_RESET,        0x7f },
+               { OV511_REG_BUS, R51x_SYS_INIT,         0x01 },
+               { OV511_REG_BUS, R51x_SYS_RESET,        0x7f },
                { OV511_REG_BUS, R51x_SYS_INIT,         0x01 },
                { OV511_REG_BUS, R51x_SYS_RESET,        0x3f },
                { OV511_REG_BUS, R51x_SYS_INIT,         0x01 },
@@ -5269,7 +5268,7 @@ ov511_configure(struct usb_ov511 *ov)
                err("Please notify " EMAIL " of the name,");
                err("manufacturer, model, and this number of your camera.");
                err("Also include the output of the detection process.");
-       } 
+       }
 
        if (ov->customid == 70)         /* USB Life TV (PAL/SECAM) */
                ov->pal = 1;
@@ -5336,17 +5335,17 @@ ov511_configure(struct usb_ov511 *ov)
 
                                        if (i2c_w(ov, 0x10, 0x00) < 0) {
                                                err("Can't determine sensor slave IDs");
-                                               goto error;
+                                               goto error;
                                        } else {
                                                if (ks0127_configure(ov) < 0) {
                                                        err("Failed to configure KS0127");
-                                                       goto error;
+                                                       goto error;
                                                }
                                        }
                                } else {
                                        if (saa7111a_configure(ov) < 0) {
                                                err("Failed to configure SAA7111A");
-                                               goto error;
+                                               goto error;
                                        }
                                }
                        } else {
@@ -5356,13 +5355,13 @@ ov511_configure(struct usb_ov511 *ov)
                } else {
                        if (ov6xx0_configure(ov) < 0) {
                                err("Failed to configure OV6xx0");
-                               goto error;
+                               goto error;
                        }
                }
        } else {
                if (ov7xx0_configure(ov) < 0) {
                        err("Failed to configure OV7xx0");
-                       goto error;
+                       goto error;
                }
        }
 
@@ -5381,12 +5380,12 @@ ov518_configure(struct usb_ov511 *ov)
        /* For 518 and 518+ */
        static struct ov511_regvals aRegvalsInit518[] = {
                { OV511_REG_BUS, R51x_SYS_RESET,        0x40 },
-               { OV511_REG_BUS, R51x_SYS_INIT,         0xe1 },
-               { OV511_REG_BUS, R51x_SYS_RESET,        0x3e },
+               { OV511_REG_BUS, R51x_SYS_INIT,         0xe1 },
+               { OV511_REG_BUS, R51x_SYS_RESET,        0x3e },
                { OV511_REG_BUS, R51x_SYS_INIT,         0xe1 },
                { OV511_REG_BUS, R51x_SYS_RESET,        0x00 },
                { OV511_REG_BUS, R51x_SYS_INIT,         0xe1 },
-               { OV511_REG_BUS, 0x46,                  0x00 }, 
+               { OV511_REG_BUS, 0x46,                  0x00 },
                { OV511_REG_BUS, 0x5d,                  0x03 },
                { OV511_DONE_BUS, 0x0, 0x00},
        };
@@ -5517,7 +5516,7 @@ ov518_configure(struct usb_ov511 *ov)
 
                        if (init_ov_sensor(ov) < 0) {
                                err("Can't determine sensor slave IDs");
-                               goto error;
+                               goto error;
                        } else {
                                err("Detected unsupported OV8xx0 sensor");
                                goto error;
@@ -5525,13 +5524,13 @@ ov518_configure(struct usb_ov511 *ov)
                } else {
                        if (ov6xx0_configure(ov) < 0) {
                                err("Failed to configure OV6xx0");
-                               goto error;
+                               goto error;
                        }
                }
        } else {
                if (ov7xx0_configure(ov) < 0) {
                        err("Failed to configure OV7xx0");
-                       goto error;
+                       goto error;
                }
        }
 
@@ -5554,41 +5553,46 @@ error:
  *  sysfs
  ***************************************************************************/
 
-static inline struct usb_ov511 *cd_to_ov(struct class_device *cd)
+static inline struct usb_ov511 *cd_to_ov(struct device *cd)
 {
        struct video_device *vdev = to_video_device(cd);
        return video_get_drvdata(vdev);
 }
 
-static ssize_t show_custom_id(struct class_device *cd, char *buf)
+static ssize_t show_custom_id(struct device *cd,
+                             struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        return sprintf(buf, "%d\n", ov->customid);
-} 
-static CLASS_DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
+}
+static DEVICE_ATTR(custom_id, S_IRUGO, show_custom_id, NULL);
 
-static ssize_t show_model(struct class_device *cd, char *buf)
+static ssize_t show_model(struct device *cd,
+                         struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        return sprintf(buf, "%s\n", ov->desc);
-} 
-static CLASS_DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
+}
+static DEVICE_ATTR(model, S_IRUGO, show_model, NULL);
 
-static ssize_t show_bridge(struct class_device *cd, char *buf)
+static ssize_t show_bridge(struct device *cd,
+                          struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        return sprintf(buf, "%s\n", symbolic(brglist, ov->bridge));
-} 
-static CLASS_DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
+}
+static DEVICE_ATTR(bridge, S_IRUGO, show_bridge, NULL);
 
-static ssize_t show_sensor(struct class_device *cd, char *buf)
+static ssize_t show_sensor(struct device *cd,
+                          struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        return sprintf(buf, "%s\n", symbolic(senlist, ov->sensor));
-} 
-static CLASS_DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
+}
+static DEVICE_ATTR(sensor, S_IRUGO, show_sensor, NULL);
 
-static ssize_t show_brightness(struct class_device *cd, char *buf)
+static ssize_t show_brightness(struct device *cd,
+                              struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        unsigned short x;
@@ -5597,10 +5601,11 @@ static ssize_t show_brightness(struct class_device *cd, char *buf)
                return -ENODEV;
        sensor_get_brightness(ov, &x);
        return sprintf(buf, "%d\n", x >> 8);
-} 
-static CLASS_DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
+}
+static DEVICE_ATTR(brightness, S_IRUGO, show_brightness, NULL);
 
-static ssize_t show_saturation(struct class_device *cd, char *buf)
+static ssize_t show_saturation(struct device *cd,
+                              struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        unsigned short x;
@@ -5609,10 +5614,11 @@ static ssize_t show_saturation(struct class_device *cd, char *buf)
                return -ENODEV;
        sensor_get_saturation(ov, &x);
        return sprintf(buf, "%d\n", x >> 8);
-} 
-static CLASS_DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
+}
+static DEVICE_ATTR(saturation, S_IRUGO, show_saturation, NULL);
 
-static ssize_t show_contrast(struct class_device *cd, char *buf)
+static ssize_t show_contrast(struct device *cd,
+                            struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        unsigned short x;
@@ -5621,10 +5627,11 @@ static ssize_t show_contrast(struct class_device *cd, char *buf)
                return -ENODEV;
        sensor_get_contrast(ov, &x);
        return sprintf(buf, "%d\n", x >> 8);
-} 
-static CLASS_DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
+}
+static DEVICE_ATTR(contrast, S_IRUGO, show_contrast, NULL);
 
-static ssize_t show_hue(struct class_device *cd, char *buf)
+static ssize_t show_hue(struct device *cd,
+                       struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        unsigned short x;
@@ -5633,10 +5640,11 @@ static ssize_t show_hue(struct class_device *cd, char *buf)
                return -ENODEV;
        sensor_get_hue(ov, &x);
        return sprintf(buf, "%d\n", x >> 8);
-} 
-static CLASS_DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
+}
+static DEVICE_ATTR(hue, S_IRUGO, show_hue, NULL);
 
-static ssize_t show_exposure(struct class_device *cd, char *buf)
+static ssize_t show_exposure(struct device *cd,
+                            struct device_attribute *attr, char *buf)
 {
        struct usb_ov511 *ov = cd_to_ov(cd);
        unsigned char exp = 0;
@@ -5645,20 +5653,52 @@ static ssize_t show_exposure(struct class_device *cd, char *buf)
                return -ENODEV;
        sensor_get_exposure(ov, &exp);
        return sprintf(buf, "%d\n", exp >> 8);
-} 
-static CLASS_DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
+}
+static DEVICE_ATTR(exposure, S_IRUGO, show_exposure, NULL);
 
-static void ov_create_sysfs(struct video_device *vdev)
+static int ov_create_sysfs(struct video_device *vdev)
 {
-       video_device_create_file(vdev, &class_device_attr_custom_id);
-       video_device_create_file(vdev, &class_device_attr_model);
-       video_device_create_file(vdev, &class_device_attr_bridge);
-       video_device_create_file(vdev, &class_device_attr_sensor);
-       video_device_create_file(vdev, &class_device_attr_brightness);
-       video_device_create_file(vdev, &class_device_attr_saturation);
-       video_device_create_file(vdev, &class_device_attr_contrast);
-       video_device_create_file(vdev, &class_device_attr_hue);
-       video_device_create_file(vdev, &class_device_attr_exposure);
+       int rc;
+
+       rc = video_device_create_file(vdev, &dev_attr_custom_id);
+       if (rc) goto err;
+       rc = video_device_create_file(vdev, &dev_attr_model);
+       if (rc) goto err_id;
+       rc = video_device_create_file(vdev, &dev_attr_bridge);
+       if (rc) goto err_model;
+       rc = video_device_create_file(vdev, &dev_attr_sensor);
+       if (rc) goto err_bridge;
+       rc = video_device_create_file(vdev, &dev_attr_brightness);
+       if (rc) goto err_sensor;
+       rc = video_device_create_file(vdev, &dev_attr_saturation);
+       if (rc) goto err_bright;
+       rc = video_device_create_file(vdev, &dev_attr_contrast);
+       if (rc) goto err_sat;
+       rc = video_device_create_file(vdev, &dev_attr_hue);
+       if (rc) goto err_contrast;
+       rc = video_device_create_file(vdev, &dev_attr_exposure);
+       if (rc) goto err_hue;
+
+       return 0;
+
+err_hue:
+       video_device_remove_file(vdev, &dev_attr_hue);
+err_contrast:
+       video_device_remove_file(vdev, &dev_attr_contrast);
+err_sat:
+       video_device_remove_file(vdev, &dev_attr_saturation);
+err_bright:
+       video_device_remove_file(vdev, &dev_attr_brightness);
+err_sensor:
+       video_device_remove_file(vdev, &dev_attr_sensor);
+err_bridge:
+       video_device_remove_file(vdev, &dev_attr_bridge);
+err_model:
+       video_device_remove_file(vdev, &dev_attr_model);
+err_id:
+       video_device_remove_file(vdev, &dev_attr_custom_id);
+err:
+       return rc;
 }
 
 /****************************************************************************
@@ -5817,7 +5857,11 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
             ov->vdev->minor);
 
        usb_set_intfdata(intf, ov);
-       ov_create_sysfs(ov->vdev);
+       if (ov_create_sysfs(ov->vdev)) {
+               err("ov_create_sysfs failed");
+               goto error;
+       }
+
        return 0;
 
 error: