nfsd4: reshuffle lease-setting code to allow reuse
[safe/jmp/linux-2.6] / drivers / hid / hid-pl.c
index a1d1fb9..c6d7dbc 100644 (file)
@@ -9,9 +9,12 @@
  *   - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT)
  *
  *  0e8f:0003 "GreenAsia Inc.    USB Joystick     "
- *   - tested with K??ng Gaming gamepad
+ *   - tested with König Gaming gamepad
  *
- *  Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
+ *  0e8f:0003 "GASIA USB Gamepad"
+ *   - another version of the König gamepad
+ *
+ *  Copyright (c) 2007, 2009 Anssi Hannula <anssi.hannula@gmail.com>
  */
 
 /*
@@ -46,6 +49,8 @@
 
 struct plff_device {
        struct hid_report *report;
+       s32 *strong;
+       s32 *weak;
 };
 
 static int hid_plff_play(struct input_dev *dev, void *data,
@@ -62,8 +67,8 @@ static int hid_plff_play(struct input_dev *dev, void *data,
        left = left * 0x7f / 0xffff;
        right = right * 0x7f / 0xffff;
 
-       plff->report->field[0]->value[2] = left;
-       plff->report->field[0]->value[3] = right;
+       *plff->strong = left;
+       *plff->weak = right;
        debug("running with 0x%02x 0x%02x", left, right);
        usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
 
@@ -80,6 +85,8 @@ static int plff_init(struct hid_device *hid)
        struct list_head *report_ptr = report_list;
        struct input_dev *dev;
        int error;
+       s32 *strong;
+       s32 *weak;
 
        /* The device contains one output report per physical device, all
           containing 1 field, which contains 4 ff00.0002 usages and 4 16bit
@@ -87,10 +94,15 @@ static int plff_init(struct hid_device *hid)
 
           The input reports also contain a field which contains
           8 ff00.0001 usages and 8 boolean values. Their meaning is
-          currently unknown. */
+          currently unknown.
+          
+          A version of the 0e8f:0003 exists that has all the values in
+          separate fields and misses the extra input field, thus resembling
+          Zeroplus (hid-zpff) devices.
+       */
 
        if (list_empty(report_list)) {
-               printk(KERN_ERR "hid-plff: no output reports found\n");
+               dev_err(&hid->dev, "no output reports found\n");
                return -ENODEV;
        }
 
@@ -99,18 +111,32 @@ static int plff_init(struct hid_device *hid)
                report_ptr = report_ptr->next;
 
                if (report_ptr == report_list) {
-                       printk(KERN_ERR "hid-plff: required output report is missing\n");
+                       dev_err(&hid->dev, "required output report is "
+                                       "missing\n");
                        return -ENODEV;
                }
 
                report = list_entry(report_ptr, struct hid_report, list);
                if (report->maxfield < 1) {
-                       printk(KERN_ERR "hid-plff: no fields in the report\n");
+                       dev_err(&hid->dev, "no fields in the report\n");
                        return -ENODEV;
                }
 
-               if (report->field[0]->report_count < 4) {
-                       printk(KERN_ERR "hid-plff: not enough values in the field\n");
+               if (report->field[0]->report_count >= 4) {
+                       report->field[0]->value[0] = 0x00;
+                       report->field[0]->value[1] = 0x00;
+                       strong = &report->field[0]->value[2];
+                       weak = &report->field[0]->value[3];
+                       debug("detected single-field device");
+               } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
+                               report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
+                       report->field[0]->value[0] = 0x00;
+                       report->field[1]->value[0] = 0x00;
+                       strong = &report->field[2]->value[0];
+                       weak = &report->field[3]->value[0];
+                       debug("detected 4-field device");
+               } else {
+                       dev_err(&hid->dev, "not enough fields or values\n");
                        return -ENODEV;
                }
 
@@ -129,14 +155,15 @@ static int plff_init(struct hid_device *hid)
                }
 
                plff->report = report;
-               plff->report->field[0]->value[0] = 0x00;
-               plff->report->field[0]->value[1] = 0x00;
-               plff->report->field[0]->value[2] = 0x00;
-               plff->report->field[0]->value[3] = 0x00;
+               plff->strong = strong;
+               plff->weak = weak;
+
+               *strong = 0x00;
+               *weak = 0x00;
                usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
        }
 
-       printk(KERN_INFO "hid-plff: Force feedback for PantherLord/GreenAsia "
+       dev_info(&hid->dev, "Force feedback for PantherLord/GreenAsia "
               "devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
 
        return 0;
@@ -177,7 +204,9 @@ err:
 static const struct hid_device_id pl_devices[] = {
        { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR),
                .driver_data = 1 }, /* Twin USB Joystick */
-       { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, /* GreenAsia Inc. USB Joystick */
+       { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PCS_ADAPTOR),
+               .driver_data = 1 }, /* Twin USB Joystick */
+       { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), },
        { }
 };
 MODULE_DEVICE_TABLE(hid, pl_devices);
@@ -188,12 +217,12 @@ static struct hid_driver pl_driver = {
        .probe = pl_probe,
 };
 
-static int pl_init(void)
+static int __init pl_init(void)
 {
        return hid_register_driver(&pl_driver);
 }
 
-static void pl_exit(void)
+static void __exit pl_exit(void)
 {
        hid_unregister_driver(&pl_driver);
 }
@@ -201,5 +230,3 @@ static void pl_exit(void)
 module_init(pl_init);
 module_exit(pl_exit);
 MODULE_LICENSE("GPL");
-
-HID_COMPAT_LOAD_DRIVER(pantherlord);