fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / input / joystick / iforce / iforce-packets.c
index 58728eb..808f059 100644 (file)
@@ -139,7 +139,11 @@ printk(KERN_DEBUG "iforce-packets.c: control_playback %d %d\n", id, value);
 static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
 {
        int i;
-       for (i=0; i<iforce->dev.ff_effects_max; ++i) {
+
+       if (!iforce->dev->ff)
+               return 0;
+
+       for (i = 0; i < iforce->dev->ff->max_effects; ++i) {
                if (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags) &&
                    (iforce->core_effects[i].mod1_chunk.start == addr ||
                     iforce->core_effects[i].mod2_chunk.start == addr)) {
@@ -151,9 +155,9 @@ static int mark_core_as_ready(struct iforce *iforce, unsigned short addr)
        return -1;
 }
 
-void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data, struct pt_regs *regs)
+void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
 {
-       struct input_dev *dev = &iforce->dev;
+       struct input_dev *dev = iforce->dev;
        int i;
        static int being_used = 0;
 
@@ -166,9 +170,9 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
                iforce->expect_packet = 0;
                iforce->ecmd = cmd;
                memcpy(iforce->edata, data, IFORCE_MAX_LENGTH);
-               wake_up(&iforce->wait);
        }
 #endif
+       wake_up(&iforce->wait);
 
        if (!iforce->type) {
                being_used--;
@@ -179,9 +183,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
 
                case 0x01:      /* joystick position data */
                case 0x03:      /* wheel position data */
-
-                       input_regs(dev, regs);
-
                        if (HI(cmd) == 1) {
                                input_report_abs(dev, ABS_X, (__s16) (((__s16)data[1] << 8) | data[0]));
                                input_report_abs(dev, ABS_Y, (__s16) (((__s16)data[3] << 8) | data[2]));
@@ -220,7 +221,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
                        break;
 
                case 0x02:      /* status report */
-                       input_regs(dev, regs);
                        input_report_key(dev, BTN_DEAD, data[0] & 0x02);
                        input_sync(dev);
 
@@ -228,19 +228,17 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
                        i = data[1] & 0x7f;
                        if (data[1] & 0x80) {
                                if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
-                               /* Report play event */
-                               input_report_ff_status(dev, i, FF_STATUS_PLAYING);
+                                       /* Report play event */
+                                       input_report_ff_status(dev, i, FF_STATUS_PLAYING);
                                }
-                       }
-                       else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
+                       } else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
                                /* Report stop event */
                                input_report_ff_status(dev, i, FF_STATUS_STOPPED);
                        }
                        if (LO(cmd) > 3) {
                                int j;
-                               for (j=3; j<LO(cmd); j+=2) {
+                               for (j = 3; j < LO(cmd); j += 2)
                                        mark_core_as_ready(iforce, data[j] | (data[j+1]<<8));
-                               }
                        }
                        break;
        }
@@ -249,9 +247,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data,
 
 int iforce_get_id_packet(struct iforce *iforce, char *packet)
 {
-       DECLARE_WAITQUEUE(wait, current);
-       int timeout = HZ; /* 1 second */
-
        switch (iforce->bus) {
 
        case IFORCE_USB:
@@ -260,22 +255,13 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
                iforce->cr.bRequest = packet[0];
                iforce->ctrl->dev = iforce->usbdev;
 
-               set_current_state(TASK_INTERRUPTIBLE);
-               add_wait_queue(&iforce->wait, &wait);
-
-               if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC)) {
-                       set_current_state(TASK_RUNNING);
-                       remove_wait_queue(&iforce->wait, &wait);
+               if (usb_submit_urb(iforce->ctrl, GFP_ATOMIC))
                        return -1;
-               }
 
-               while (timeout && iforce->ctrl->status == -EINPROGRESS)
-                       timeout = schedule_timeout(timeout);
+               wait_event_interruptible_timeout(iforce->wait,
+                       iforce->ctrl->status != -EINPROGRESS, HZ);
 
-               set_current_state(TASK_RUNNING);
-               remove_wait_queue(&iforce->wait, &wait);
-
-               if (!timeout) {
+               if (iforce->ctrl->status) {
                        usb_unlink_urb(iforce->ctrl);
                        return -1;
                }
@@ -290,16 +276,10 @@ int iforce_get_id_packet(struct iforce *iforce, char *packet)
                iforce->expect_packet = FF_CMD_QUERY;
                iforce_send_packet(iforce, FF_CMD_QUERY, packet);
 
-               set_current_state(TASK_INTERRUPTIBLE);
-               add_wait_queue(&iforce->wait, &wait);
-
-               while (timeout && iforce->expect_packet)
-                       timeout = schedule_timeout(timeout);
-
-               set_current_state(TASK_RUNNING);
-               remove_wait_queue(&iforce->wait, &wait);
+               wait_event_interruptible_timeout(iforce->wait,
+                       !iforce->expect_packet, HZ);
 
-               if (!timeout) {
+               if (iforce->expect_packet) {
                        iforce->expect_packet = 0;
                        return -1;
                }