Commit 38d10769 authored by Dmitry Torokhov's avatar Dmitry Torokhov

Input: iforce - introduce transport ops

In order to tease apart the driver into core and transport modules, let's
introduce transport operations and make "xmit" the very first one such
operation.
Tested-by: default avatarTim Schumacher <timschumi@gmx.de>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent f7f3651e
...@@ -91,25 +91,9 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data) ...@@ -91,25 +91,9 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data)
/* /*
* If necessary, start the transmission * If necessary, start the transmission
*/ */
switch (iforce->bus) { if (empty)
iforce->xport_ops->xmit(iforce);
#ifdef CONFIG_JOYSTICK_IFORCE_232
case IFORCE_232:
if (empty)
iforce_serial_xmit(iforce);
break;
#endif
#ifdef CONFIG_JOYSTICK_IFORCE_USB
case IFORCE_USB:
if (iforce->usbdev && empty &&
!test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)) {
iforce_usb_xmit(iforce);
}
break;
#endif
}
return 0; return 0;
} }
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "iforce.h" #include "iforce.h"
void iforce_serial_xmit(struct iforce *iforce) static void iforce_serio_xmit(struct iforce *iforce)
{ {
unsigned char cs; unsigned char cs;
int i; int i;
...@@ -67,11 +67,15 @@ void iforce_serial_xmit(struct iforce *iforce) ...@@ -67,11 +67,15 @@ void iforce_serial_xmit(struct iforce *iforce)
spin_unlock_irqrestore(&iforce->xmit_lock, flags); spin_unlock_irqrestore(&iforce->xmit_lock, flags);
} }
static const struct iforce_xport_ops iforce_serio_xport_ops = {
.xmit = iforce_serio_xmit,
};
static void iforce_serio_write_wakeup(struct serio *serio) static void iforce_serio_write_wakeup(struct serio *serio)
{ {
struct iforce *iforce = serio_get_drvdata(serio); struct iforce *iforce = serio_get_drvdata(serio);
iforce_serial_xmit(iforce); iforce_serio_xmit(iforce);
} }
static irqreturn_t iforce_serio_irq(struct serio *serio, static irqreturn_t iforce_serio_irq(struct serio *serio,
...@@ -129,6 +133,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) ...@@ -129,6 +133,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
if (!iforce) if (!iforce)
return -ENOMEM; return -ENOMEM;
iforce->xport_ops = &iforce_serio_xport_ops;
iforce->bus = IFORCE_232; iforce->bus = IFORCE_232;
iforce->serio = serio; iforce->serio = serio;
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include "iforce.h" #include "iforce.h"
void iforce_usb_xmit(struct iforce *iforce) static void __iforce_usb_xmit(struct iforce *iforce)
{ {
int n, c; int n, c;
unsigned long flags; unsigned long flags;
...@@ -69,6 +69,16 @@ void iforce_usb_xmit(struct iforce *iforce) ...@@ -69,6 +69,16 @@ void iforce_usb_xmit(struct iforce *iforce)
spin_unlock_irqrestore(&iforce->xmit_lock, flags); spin_unlock_irqrestore(&iforce->xmit_lock, flags);
} }
static void iforce_usb_xmit(struct iforce *iforce)
{
if (!test_and_set_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags))
__iforce_usb_xmit(iforce);
}
static const struct iforce_xport_ops iforce_usb_xport_ops = {
.xmit = iforce_usb_xmit,
};
static void iforce_usb_irq(struct urb *urb) static void iforce_usb_irq(struct urb *urb)
{ {
struct iforce *iforce = urb->context; struct iforce *iforce = urb->context;
...@@ -113,7 +123,7 @@ static void iforce_usb_out(struct urb *urb) ...@@ -113,7 +123,7 @@ static void iforce_usb_out(struct urb *urb)
return; return;
} }
iforce_usb_xmit(iforce); __iforce_usb_xmit(iforce);
wake_up(&iforce->wait); wake_up(&iforce->wait);
} }
...@@ -155,6 +165,7 @@ static int iforce_usb_probe(struct usb_interface *intf, ...@@ -155,6 +165,7 @@ static int iforce_usb_probe(struct usb_interface *intf,
if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL))) if (!(iforce->ctrl = usb_alloc_urb(0, GFP_KERNEL)))
goto fail; goto fail;
iforce->xport_ops = &iforce_usb_xport_ops;
iforce->bus = IFORCE_USB; iforce->bus = IFORCE_USB;
iforce->usbdev = dev; iforce->usbdev = dev;
iforce->intf = intf; iforce->intf = intf;
......
...@@ -93,9 +93,16 @@ struct iforce_device { ...@@ -93,9 +93,16 @@ struct iforce_device {
signed short *ff; signed short *ff;
}; };
struct iforce;
struct iforce_xport_ops {
void (*xmit)(struct iforce *iforce);
};
struct iforce { struct iforce {
struct input_dev *dev; /* Input device interface */ struct input_dev *dev; /* Input device interface */
struct iforce_device *type; struct iforce_device *type;
const struct iforce_xport_ops *xport_ops;
int bus; int bus;
unsigned char data[IFORCE_MAX_LENGTH]; unsigned char data[IFORCE_MAX_LENGTH];
...@@ -141,12 +148,6 @@ struct iforce { ...@@ -141,12 +148,6 @@ struct iforce {
/* Public functions */ /* Public functions */
/* iforce-serio.c */
void iforce_serial_xmit(struct iforce *iforce);
/* iforce-usb.c */
void iforce_usb_xmit(struct iforce *iforce);
/* iforce-main.c */ /* iforce-main.c */
int iforce_init_device(struct iforce *iforce); int iforce_init_device(struct iforce *iforce);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment