linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / drivers / usb / media / konicawc.c
index 08521a2..e2ede58 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/input.h>
+#include <linux/usb_input.h>
 
 #include "usbvideo.h"
 
@@ -76,14 +77,14 @@ static int saturation =     MAX_SATURATION/2;
 static int sharpness = MAX_SHARPNESS/2;
 static int whitebal =  3*(MAX_WHITEBAL/4);
 
-static int spd_to_iface[] = { 1, 0, 3, 2, 4, 5, 6 };
+static const int spd_to_iface[] = { 1, 0, 3, 2, 4, 5, 6 };
 
 /* These FPS speeds are from the windows config box. They are
  * indexed on size (0-2) and speed (0-6). Divide by 3 to get the
  * real fps.
  */
 
-static int spd_to_fps[][7] = { { 24, 40, 48, 60, 72, 80, 100 },
+static const int spd_to_fps[][7] = { { 24, 40, 48, 60, 72, 80, 100 },
                               { 24, 40, 48, 60, 72, 80, 100 },
                               { 18, 30, 36, 45, 54, 60, 75  },
                               { 6,  10, 12, 15, 18, 21, 25  } };
@@ -94,7 +95,7 @@ struct cam_size {
        u8      cmd;
 };
 
-static struct cam_size camera_sizes[] = { { 160, 120, 0x7 },
+static const struct cam_size camera_sizes[] = { { 160, 120, 0x7 },
                                          { 160, 136, 0xa },
                                          { 176, 144, 0x4 },
                                          { 320, 240, 0x5 } };
@@ -118,7 +119,7 @@ struct konicawc {
        int yplanesz;           /* Number of bytes in the Y plane */
        unsigned int buttonsts:1;
 #ifdef CONFIG_INPUT
-       struct input_dev input;
+       struct input_dev *input;
        char input_physname[64];
 #endif
 };
@@ -217,6 +218,57 @@ static void konicawc_adjust_picture(struct uvd *uvd)
        konicawc_camera_on(uvd);
 }
 
+#ifdef CONFIG_INPUT
+
+static void konicawc_register_input(struct konicawc *cam, struct usb_device *dev)
+{
+       struct input_dev *input_dev;
+
+       usb_make_path(dev, cam->input_physname, sizeof(cam->input_physname));
+       strncat(cam->input_physname, "/input0", sizeof(cam->input_physname));
+
+       cam->input = input_dev = input_allocate_device();
+       if (!input_dev) {
+               warn("Not enough memory for camera's input device\n");
+               return;
+       }
+
+       input_dev->name = "Konicawc snapshot button";
+       input_dev->phys = cam->input_physname;
+       usb_to_input_id(dev, &input_dev->id);
+       input_dev->cdev.dev = &dev->dev;
+
+       input_dev->evbit[0] = BIT(EV_KEY);
+       input_dev->keybit[LONG(BTN_0)] = BIT(BTN_0);
+
+       input_dev->private = cam;
+
+       input_register_device(cam->input);
+}
+
+static void konicawc_unregister_input(struct konicawc *cam)
+{
+       if (cam->input) {
+               input_unregister_device(cam->input);
+               cam->input = NULL;
+       }
+}
+
+static void konicawc_report_buttonstat(struct konicawc *cam)
+{
+       if (cam->input) {
+               input_report_key(cam->input, BTN_0, cam->buttonsts);
+               input_sync(cam->input);
+       }
+}
+
+#else
+
+static inline void konicawc_register_input(struct konicawc *cam, struct usb_device *dev) { }
+static inline void konicawc_unregister_input(struct konicawc *cam) { }
+static inline void konicawc_report_buttonstat(struct konicawc *cam) { }
+
+#endif /* CONFIG_INPUT */
 
 static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct urb *stsurb)
 {
@@ -272,10 +324,7 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
                if(button != cam->buttonsts) {
                        DEBUG(2, "button: %sclicked", button ? "" : "un");
                        cam->buttonsts = button;
-#ifdef CONFIG_INPUT
-                       input_report_key(&cam->input, BTN_0, cam->buttonsts);
-                       input_sync(&cam->input);
-#endif
+                       konicawc_report_buttonstat(cam);
                }
 
                if(sts == 0x01) { /* drop frame */
@@ -644,9 +693,9 @@ static int konicawc_set_video_mode(struct uvd *uvd, struct video_window *vw)
        RingQueue_Flush(&uvd->dp);
        cam->lastframe = -2;
        if(uvd->curframe != -1) {
-         uvd->frame[uvd->curframe].curline = 0;
-         uvd->frame[uvd->curframe].seqRead_Length = 0;
-         uvd->frame[uvd->curframe].seqRead_Index = 0;
+               uvd->frame[uvd->curframe].curline = 0;
+               uvd->frame[uvd->curframe].seqRead_Length = 0;
+               uvd->frame[uvd->curframe].seqRead_Index = 0;
        }
 
        konicawc_start_data(uvd);
@@ -717,7 +766,6 @@ static void konicawc_configure_video(struct uvd *uvd)
        DEBUG(1, "setting initial values");
 }
 
-
 static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id *devid)
 {
        struct usb_device *dev = interface_to_usbdev(intf);
@@ -838,24 +886,8 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
                        err("usbvideo_RegisterVideoDevice() failed.");
                        uvd = NULL;
                }
-#ifdef CONFIG_INPUT
-               /* Register input device for button */
-               memset(&cam->input, 0, sizeof(struct input_dev));
-               cam->input.name = "Konicawc snapshot button";
-               cam->input.private = cam;
-               cam->input.evbit[0] = BIT(EV_KEY);
-               cam->input.keybit[LONG(BTN_0)] = BIT(BTN_0);
-               cam->input.id.bustype = BUS_USB;
-               cam->input.id.vendor = le16_to_cpu(dev->descriptor.idVendor);
-               cam->input.id.product = le16_to_cpu(dev->descriptor.idProduct);
-               cam->input.id.version = le16_to_cpu(dev->descriptor.bcdDevice);
-               input_register_device(&cam->input);
-               
-               usb_make_path(dev, cam->input_physname, 56);
-               strcat(cam->input_physname, "/input0");
-               cam->input.phys = cam->input_physname;
-               info("konicawc: %s on %s\n", cam->input.name, cam->input.phys);
-#endif
+
+               konicawc_register_input(cam, dev);
        }
 
        if (uvd) {
@@ -871,10 +903,9 @@ static void konicawc_free_uvd(struct uvd *uvd)
        int i;
        struct konicawc *cam = (struct konicawc *)uvd->user_data;
 
-#ifdef CONFIG_INPUT
-       input_unregister_device(&cam->input);
-#endif
-       for (i=0; i < USBVIDEO_NUMSBUF; i++) {
+       konicawc_unregister_input(cam);
+
+       for (i = 0; i < USBVIDEO_NUMSBUF; i++) {
                usb_free_urb(cam->sts_urb[i]);
                cam->sts_urb[i] = NULL;
        }