@@ -210,67 +210,3 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)
break;
}
}
-
-int iforce_get_id_packet(struct iforce *iforce, char *packet)
-{
- switch (iforce->bus) {
-
- case IFORCE_USB: {
-#ifdef CONFIG_JOYSTICK_IFORCE_USB
- int status;
-
- iforce->cr.bRequest = packet[0];
- iforce->ctrl->dev = iforce->usbdev;
-
- status = usb_submit_urb(iforce->ctrl, GFP_KERNEL);
- if (status) {
- dev_err(&iforce->intf->dev,
- "usb_submit_urb failed %d\n", status);
- return -1;
- }
-
- wait_event_interruptible_timeout(iforce->wait,
- iforce->ctrl->status != -EINPROGRESS, HZ);
-
- if (iforce->ctrl->status) {
- dev_dbg(&iforce->intf->dev,
- "iforce->ctrl->status = %d\n",
- iforce->ctrl->status);
- usb_unlink_urb(iforce->ctrl);
- return -1;
- }
-#else
- printk(KERN_DEBUG "iforce_get_id_packet: iforce->bus = USB!\n");
-#endif
- }
- break;
-
- case IFORCE_232:
-
-#ifdef CONFIG_JOYSTICK_IFORCE_232
- iforce->expect_packet = FF_CMD_QUERY;
- iforce_send_packet(iforce, FF_CMD_QUERY, packet);
-
- wait_event_interruptible_timeout(iforce->wait,
- !iforce->expect_packet, HZ);
-
- if (iforce->expect_packet) {
- iforce->expect_packet = 0;
- return -1;
- }
-#else
- dev_err(&iforce->dev->dev,
- "iforce_get_id_packet: iforce->bus = SERIO!\n");
-#endif
- break;
-
- default:
- dev_err(&iforce->dev->dev,
- "iforce_get_id_packet: iforce->bus = %d\n",
- iforce->bus);
- break;
- }
-
- return -(iforce->edata[0] != packet[0]);
-}
-
@@ -67,8 +67,25 @@ static void iforce_serio_xmit(struct iforce *iforce)
spin_unlock_irqrestore(&iforce->xmit_lock, flags);
}
+static int iforce_serio_get_id(struct iforce *iforce, u8 *packet)
+{
+ iforce->expect_packet = FF_CMD_QUERY;
+ iforce_send_packet(iforce, FF_CMD_QUERY, packet);
+
+ wait_event_interruptible_timeout(iforce->wait,
+ !iforce->expect_packet, HZ);
+
+ if (iforce->expect_packet) {
+ iforce->expect_packet = 0;
+ return -EIO;
+ }
+
+ return -(iforce->edata[0] != packet[0]);
+}
+
static const struct iforce_xport_ops iforce_serio_xport_ops = {
.xmit = iforce_serio_xmit,
+ .get_id = iforce_serio_get_id,
};
static void iforce_serio_write_wakeup(struct serio *serio)
@@ -75,8 +75,37 @@ static void iforce_usb_xmit(struct iforce *iforce)
__iforce_usb_xmit(iforce);
}
+static int iforce_usb_get_id(struct iforce *iforce, u8 *packet)
+{
+ int status;
+
+ iforce->cr.bRequest = packet[0];
+ iforce->ctrl->dev = iforce->usbdev;
+
+ status = usb_submit_urb(iforce->ctrl, GFP_KERNEL);
+ if (status) {
+ dev_err(&iforce->intf->dev,
+ "usb_submit_urb failed %d\n", status);
+ return -EIO;
+ }
+
+ wait_event_interruptible_timeout(iforce->wait,
+ iforce->ctrl->status != -EINPROGRESS, HZ);
+
+ if (iforce->ctrl->status) {
+ dev_dbg(&iforce->intf->dev,
+ "iforce->ctrl->status = %d\n",
+ iforce->ctrl->status);
+ usb_unlink_urb(iforce->ctrl);
+ return -EIO;
+ }
+
+ return -(iforce->edata[0] != packet[0]);
+}
+
static const struct iforce_xport_ops iforce_usb_xport_ops = {
.xmit = iforce_usb_xmit,
+ .get_id = iforce_usb_get_id,
};
static void iforce_usb_irq(struct urb *urb)
@@ -97,6 +97,7 @@ struct iforce;
struct iforce_xport_ops {
void (*xmit)(struct iforce *iforce);
+ int (*get_id)(struct iforce *iforce, u8* id);
};
struct iforce {
@@ -146,6 +147,10 @@ struct iforce {
/* Encode a time value */
#define TIME_SCALE(a) (a)
+static inline int iforce_get_id_packet(struct iforce *iforce, u8* id)
+{
+ return iforce->xport_ops->get_id(iforce, id);
+}
/* Public functions */
/* iforce-main.c */
@@ -156,7 +161,6 @@ int iforce_control_playback(struct iforce*, u16 id, unsigned int);
void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data);
int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data);
void iforce_dump_packet(struct iforce *iforce, char *msg, u16 cmd, unsigned char *data);
-int iforce_get_id_packet(struct iforce *iforce, char *packet);
/* iforce-ff.c */
int iforce_upload_periodic(struct iforce *, struct ff_effect *, struct ff_effect *);
To avoid #ifdef-ing out parts of the code and having conditionals in normal control flow, let's define "get_id" transport method and move implementation into respective transport modules. Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> --- .../input/joystick/iforce/iforce-packets.c | 64 ------------------- drivers/input/joystick/iforce/iforce-serio.c | 17 +++++ drivers/input/joystick/iforce/iforce-usb.c | 29 +++++++++ drivers/input/joystick/iforce/iforce.h | 6 +- 4 files changed, 51 insertions(+), 65 deletions(-)