Input: iforce - remove "being used" silliness
Subsystems (2)
Dmitry Torokhov
maintainerPATCH 1/20 Input: iforce - remove "being used" silliness
The kernel is supposed to handle multiple devices, static flags in packet handling code will never work.
---
This is a random assortment of iforce patches that I made a few weeks back.
Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome).
Thanks!
drivers/input/joystick/iforce/iforce-packets.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +1 -10
@@ -149,12 +149,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) {struct input_dev *dev = iforce->dev;int i; -static int being_used =0 ; - -if (being_used) -dev_warn (&iforce->dev->dev, -"re-entrant call to iforce_process %d\n" , being_used); - being_used++;#ifdef CONFIG_JOYSTICK_IFORCE_232 if (HI (iforce->expect_packet) ==HI (cmd)) {
@@ -165,10 +159,8 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)#endif wake_up (&iforce->wait); -if (!iforce->type) { - being_used--; +if (!iforce->type)return ; - }switch (HI (cmd)) {
@@ -233,7 +225,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data) }break ; } - being_used--; }int iforce_get_id_packet (struct iforce *iforce,char *packet)
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 2/20 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.
--- .../input/joystick/iforce/iforce-packets.c | 20 ++----------------- drivers/input/joystick/iforce/iforce-serio.c | 9 +++++++-- drivers/input/joystick/iforce/iforce-usb.c | 15 ++++++++++++-- drivers/input/joystick/iforce/iforce.h | 13 ++++++------ 4 files changed, 29 insertions(+), 28 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +2 -18
@@ -91,25 +91,9 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data)/* * If necessary, start the transmission */ -switch (iforce->bus) { - -#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 (empty) + iforce->xport_ops->xmit (iforce); -if (iforce->usbdev && empty && - !test_and_set_bit (IFORCE_XMIT_RUNNING , iforce->xmit_flags)) { - -iforce_usb_xmit (iforce); - } -break ; -#endif - }return 0 ; }
drivers/input/joystick/iforce/iforce-serio.c +7 -2
@@ -23,7 +23,7 @@#include "iforce.h" -void iforce_serial_xmit (struct iforce *iforce) +static void iforce_serio_xmit (struct iforce *iforce) {unsigned char cs;int i;
@@ -67,11 +67,15 @@ void iforce_serial_xmit(struct iforce *iforce)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) {struct iforce *iforce =serio_get_drvdata (serio); -iforce_serial_xmit (iforce); +iforce_serio_xmit (iforce); } 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)if (!iforce)return -ENOMEM ; + iforce->xport_ops = &iforce_serio_xport_ops; iforce->bus =IFORCE_232 ; iforce->serio = serio;
drivers/input/joystick/iforce/iforce-usb.c +13 -2
@@ -23,7 +23,7 @@#include "iforce.h" -void iforce_usb_xmit (struct iforce *iforce) +static void __iforce_usb_xmit (struct iforce *iforce) {int n, c;unsigned long flags;
@@ -69,6 +69,16 @@ void iforce_usb_xmit(struct iforce *iforce)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) {struct iforce *iforce = urb->context;
@@ -113,7 +123,7 @@ static void iforce_usb_out(struct urb *urb)return ; } -iforce_usb_xmit (iforce); +__iforce_usb_xmit (iforce);wake_up (&iforce->wait); }
@@ -155,6 +165,7 @@ static int iforce_usb_probe(struct usb_interface *intf,if (!(iforce->ctrl =usb_alloc_urb (0 ,GFP_KERNEL ))) goto fail; + iforce->xport_ops = &iforce_usb_xport_ops; iforce->bus =IFORCE_USB ; iforce->usbdev = dev; iforce->intf = intf;
drivers/input/joystick/iforce/iforce.h +7 -6
@@ -93,9 +93,16 @@ struct iforce_device {signed short *ff; }; +struct iforce ; + +struct iforce_xport_ops { +void (*xmit)(struct iforce *iforce); +}; +struct iforce {struct input_dev *dev;/* Input device interface */ struct iforce_device *type; +const struct iforce_xport_ops *xport_ops;int bus;unsigned char data[IFORCE_MAX_LENGTH ];
@@ -141,12 +148,6 @@ struct iforce {/* 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 */ int iforce_init_device (struct iforce *iforce);
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 3/20 Input: iforce - move get_id to the transport operations
In reply to Dmitry TorokhovTo 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.
--- .../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(-)
drivers/input/joystick/iforce/iforce-packets.c +0 -64
@@ -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 ]); -} -
drivers/input/joystick/iforce/iforce-serio.c +17 -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)
drivers/input/joystick/iforce/iforce-usb.c +29 -0
@@ -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)
drivers/input/joystick/iforce/iforce.h +5 -1
@@ -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 *);
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 4/20 Input: iforce - move command completion handling to serio code
In reply to Dmitry TorokhovContinue teasing apart protocol-specific bits from core into transport modules. This time move RS232-specific command completion handling from core to iforce-serio module.
--- drivers/input/joystick/iforce/iforce-packets.c | 7 ------- drivers/input/joystick/iforce/iforce-serio.c | 12 +++++++++++- 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +0 -7
@@ -134,13 +134,6 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)struct input_dev *dev = iforce->dev;int i; -#ifdef CONFIG_JOYSTICK_IFORCE_232 -if (HI (iforce->expect_packet) ==HI (cmd)) { - iforce->expect_packet =0 ; - iforce->ecmd = cmd; -memcpy (iforce->edata, data,IFORCE_MAX_LENGTH ); - } -#endif wake_up (&iforce->wait);if (!iforce->type)
drivers/input/joystick/iforce/iforce-serio.c +11 -1
@@ -130,7 +130,17 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, }if (iforce->idx == iforce->len) { -iforce_process_packet (iforce, (iforce->id <<8 ) | iforce->idx, iforce->data); +u16 cmd = (iforce->id <<8 ) | iforce->idx; + +/* Handle command completion */ +if (HI (iforce->expect_packet) ==HI (cmd)) { + iforce->expect_packet =0 ; + iforce->ecmd = cmd; +memcpy (iforce->edata, iforce->data,IFORCE_MAX_LENGTH ); + } + +iforce_process_packet (iforce, cmd, iforce->data); + iforce->pkt =0 ; iforce->id =0 ; iforce->len =0 ;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 5/20 Input: iforce - introduce start and stop io transport ops
In reply to Dmitry TorokhovAdd start_io() and stop_io() transport methods so that core does not have to know the details.
--- drivers/input/joystick/iforce/iforce-main.c | 25 ++------------------ drivers/input/joystick/iforce/iforce-serio.c | 13 ++++++++++ drivers/input/joystick/iforce/iforce-usb.c | 17 +++++++++++++ drivers/input/joystick/iforce/iforce.h | 2 ++ 4 files changed, 34 insertions(+), 23 deletions(-)
drivers/input/joystick/iforce/iforce-main.c +2 -23
@@ -185,15 +185,7 @@ static int iforce_open(struct input_dev *dev) {struct iforce *iforce =input_get_drvdata (dev); -switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB -case IFORCE_USB : - iforce->irq->dev = iforce->usbdev; -if (usb_submit_urb (iforce->irq,GFP_KERNEL )) -return -EIO ; -break ; -#endif - } + iforce->xport_ops->start_io (iforce);if (test_bit (EV_FF , dev->evbit)) {/* Enable force feedback */
@@ -226,20 +218,7 @@ static void iforce_close(struct input_dev *dev) !test_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)); } -switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB -case IFORCE_USB : -usb_kill_urb (iforce->irq); -usb_kill_urb (iforce->out); -usb_kill_urb (iforce->ctrl); -break ; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 -case IFORCE_232 : -//TODO: Wait for the last packets to be sent -break ; -#endif - } + iforce->xport_ops->stop_io (iforce); }int iforce_init_device (struct iforce *iforce)
drivers/input/joystick/iforce/iforce-serio.c +13 -0
@@ -83,9 +83,22 @@ static int iforce_serio_get_id(struct iforce *iforce, u8 *packet)return -(iforce->edata[0 ] != packet[0 ]); } +static int iforce_serio_start_io (struct iforce *iforce) +{ +/* No special handling required */ +return 0 ; +} + +static void iforce_serio_stop_io (struct iforce *iforce) +{ +//TODO: Wait for the last packets to be sent +} +static const struct iforce_xport_ops iforce_serio_xport_ops = { .xmit = iforce_serio_xmit, .get_id = iforce_serio_get_id, + .start_io = iforce_serio_start_io, + .stop_io = iforce_serio_stop_io, };static void iforce_serio_write_wakeup (struct serio *serio)
drivers/input/joystick/iforce/iforce-usb.c +17 -0
@@ -103,9 +103,26 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet)return -(iforce->edata[0 ] != packet[0 ]); } +static int iforce_usb_start_io (struct iforce *iforce) +{ +if (usb_submit_urb (iforce->irq,GFP_KERNEL )) +return -EIO ; + +return 0 ; +} + +static void iforce_usb_stop_io (struct iforce *iforce) +{ +usb_kill_urb (iforce->irq); +usb_kill_urb (iforce->out); +usb_kill_urb (iforce->ctrl); +} +static const struct iforce_xport_ops iforce_usb_xport_ops = { .xmit = iforce_usb_xmit, .get_id = iforce_usb_get_id, + .start_io = iforce_usb_start_io, + .stop_io = iforce_usb_stop_io, };static void iforce_usb_irq (struct urb *urb)
drivers/input/joystick/iforce/iforce.h +2 -0
@@ -98,6 +98,8 @@ struct iforce;struct iforce_xport_ops {void (*xmit)(struct iforce *iforce);int (*get_id)(struct iforce *iforce,u8 * id); +int (*start_io)(struct iforce *iforce); +void (*stop_io)(struct iforce *iforce); };struct iforce {
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 6/20 Input: iforce - add bus type and parent arguments to iforce_init_device()
In reply to Dmitry TorokhovNote that the parent device for the USB-connected controllers is now USB interface instead of USB device.
--- drivers/input/joystick/iforce/iforce-main.c | 19 ++++--------------- drivers/input/joystick/iforce/iforce-serio.c | 2 +- drivers/input/joystick/iforce/iforce-usb.c | 2 +- drivers/input/joystick/iforce/iforce.h | 3 ++- 4 files changed, 8 insertions(+), 18 deletions(-)
drivers/input/joystick/iforce/iforce-main.c +4 -15
@@ -221,7 +221,8 @@ static void iforce_close(struct input_dev *dev) iforce->xport_ops->stop_io (iforce); } -int iforce_init_device (struct iforce *iforce) +int iforce_init_device (struct device *parent,u16 bustype, +struct iforce *iforce) {struct input_dev *input_dev;struct ff_device *ff;
@@ -243,20 +244,8 @@ int iforce_init_device(struct iforce *iforce)* Input device fields. */ -switch (iforce->bus) { -#ifdef CONFIG_JOYSTICK_IFORCE_USB -case IFORCE_USB : - input_dev->id.bustype =BUS_USB ; - input_dev->dev.parent = &iforce->usbdev->dev; -break ; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 -case IFORCE_232 : - input_dev->id.bustype =BUS_RS232 ; - input_dev->dev.parent = &iforce->serio->dev; -break ; -#endif - } + input_dev->id.bustype = bustype; + input_dev->dev.parent = parent;input_set_drvdata (input_dev, iforce);
drivers/input/joystick/iforce/iforce-serio.c +1 -1
@@ -183,7 +183,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)if (err) goto fail1; - err =iforce_init_device (iforce); + err =iforce_init_device (&serio->dev,BUS_RS232 , iforce);if (err) goto fail2;
drivers/input/joystick/iforce/iforce-usb.c +1 -1
@@ -229,7 +229,7 @@ static int iforce_usb_probe(struct usb_interface *intf,usb_fill_control_urb (iforce->ctrl, dev,usb_rcvctrlpipe (dev,0 ), (void *) &iforce->cr, iforce->edata,16 , iforce_usb_ctrl, iforce); - err =iforce_init_device (iforce); + err =iforce_init_device (&intf->dev,BUS_USB , iforce);if (err) goto fail;
drivers/input/joystick/iforce/iforce.h +2 -1
@@ -156,7 +156,8 @@ static inline int iforce_get_id_packet(struct iforce *iforce, u8* id)/* Public functions */ /* iforce-main.c */ -int iforce_init_device (struct iforce *iforce); +int iforce_init_device (struct device *parent,u16 bustype, +struct iforce *iforce);/* iforce-packets.c */ int iforce_control_playback (struct iforce *,u16 id,unsigned int );
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 7/20 Input: iforce - move transport data into transport modules
In reply to Dmitry TorokhovThis moves transport-specific data from main iforce structure into transport modules.
--- drivers/input/joystick/iforce/iforce-serio.c | 96 ++++++++----- drivers/input/joystick/iforce/iforce-usb.c | 138 +++++++++++-------- drivers/input/joystick/iforce/iforce.h | 14 +- 3 files changed, 144 insertions(+), 104 deletions(-)
drivers/input/joystick/iforce/iforce-serio.c +59 -37
@@ -23,8 +23,20 @@#include "iforce.h" +struct iforce_serio { +struct iforce iforce; + +struct serio *serio; +int idx, pkt, len, id; +u8 csum; +u8 expect_packet; +}; +static void iforce_serio_xmit (struct iforce *iforce) { +struct iforce_serio *iforce_serio =container_of (iforce, + struct iforce_serio, + iforce);unsigned char cs;int i;unsigned long flags;
@@ -45,19 +57,20 @@ static void iforce_serio_xmit(struct iforce *iforce) cs =0x2b ; -serio_write (iforce->serio,0x2b ); +serio_write (iforce_serio->serio,0x2b ); -serio_write (iforce->serio, iforce->xmit.buf[iforce->xmit.tail]); +serio_write (iforce_serio->serio, iforce->xmit.buf[iforce->xmit.tail]); cs ^= iforce->xmit.buf[iforce->xmit.tail];XMIT_INC (iforce->xmit.tail,1 );for (i=iforce->xmit.buf[iforce->xmit.tail]; i >=0 ; --i) { -serio_write (iforce->serio, iforce->xmit.buf[iforce->xmit.tail]); +serio_write (iforce_serio->serio, + iforce->xmit.buf[iforce->xmit.tail]); cs ^= iforce->xmit.buf[iforce->xmit.tail];XMIT_INC (iforce->xmit.tail,1 ); } -serio_write (iforce->serio, cs); +serio_write (iforce_serio->serio, cs);if (test_and_clear_bit (IFORCE_XMIT_AGAIN , iforce->xmit_flags)) goto again;
@@ -69,14 +82,18 @@ static void iforce_serio_xmit(struct iforce *iforce)static int iforce_serio_get_id (struct iforce *iforce,u8 *packet) { - iforce->expect_packet =FF_CMD_QUERY ; +struct iforce_serio *iforce_serio =container_of (iforce, + struct iforce_serio, + iforce); + + iforce_serio->expect_packet =HI (FF_CMD_QUERY );iforce_send_packet (iforce,FF_CMD_QUERY , packet);wait_event_interruptible_timeout (iforce->wait, - !iforce->expect_packet,HZ ); + !iforce_serio->expect_packet,HZ ); -if (iforce->expect_packet) { - iforce->expect_packet =0 ; +if (iforce_serio->expect_packet) { + iforce_serio->expect_packet =0 ;return -EIO ; }
@@ -111,54 +128,56 @@ static void iforce_serio_write_wakeup(struct serio *serio)static irqreturn_t iforce_serio_irq (struct serio *serio,unsigned char data,unsigned int flags) { -struct iforce *iforce =serio_get_drvdata (serio); +struct iforce_serio *iforce_serio =serio_get_drvdata (serio); +struct iforce *iforce = &iforce_serio->iforce; -if (!iforce->pkt) { +if (!iforce_serio->pkt) {if (data ==0x2b ) - iforce->pkt =1 ; + iforce_serio->pkt =1 ; goto out; } -if (!iforce->id) { +if (!iforce_serio->id) {if (data >3 && data !=0xff ) - iforce->pkt =0 ; + iforce_serio->pkt =0 ;else - iforce->id = data; + iforce_serio->id = data; goto out; } -if (!iforce->len) { +if (!iforce_serio->len) {if (data >IFORCE_MAX_LENGTH ) { - iforce->pkt =0 ; - iforce->id =0 ; + iforce_serio->pkt =0 ; + iforce_serio->id =0 ; }else { - iforce->len = data; + iforce_serio->len = data; } goto out; } -if (iforce->idx < iforce->len) { - iforce->csum += iforce->data[iforce->idx++] = data; +if (iforce_serio->idx < iforce_serio->len) { + iforce->data[iforce_serio->idx++] = data; + iforce_serio->csum += data; goto out; } -if (iforce->idx == iforce->len) { -u16 cmd = (iforce->id <<8 ) | iforce->idx; +if (iforce_serio->idx == iforce_serio->len) { +u16 cmd = (iforce_serio->id <<8 ) | iforce_serio->idx;/* Handle command completion */ -if (HI (iforce->expect_packet) ==HI (cmd)) { - iforce->expect_packet =0 ; +if (iforce_serio->expect_packet == iforce_serio->id) { + iforce_serio->expect_packet =0 ; iforce->ecmd = cmd;memcpy (iforce->edata, iforce->data,IFORCE_MAX_LENGTH ); }iforce_process_packet (iforce, cmd, iforce->data); - iforce->pkt =0 ; - iforce->id =0 ; - iforce->len =0 ; - iforce->idx =0 ; - iforce->csum =0 ; + iforce_serio->pkt =0 ; + iforce_serio->id =0 ; + iforce_serio->len =0 ; + iforce_serio->idx =0 ; + iforce_serio->csum =0 ; } out:return IRQ_HANDLED ;
@@ -166,18 +185,21 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,static int iforce_serio_connect (struct serio *serio,struct serio_driver *drv) { +struct iforce_serio *iforce_serio;struct iforce *iforce;int err; - iforce =kzalloc (sizeof (struct iforce ),GFP_KERNEL ); -if (!iforce) + iforce_serio =kzalloc (sizeof (*iforce_serio),GFP_KERNEL ); +if (!iforce_serio)return -ENOMEM ; + iforce = &iforce_serio->iforce; + iforce->xport_ops = &iforce_serio_xport_ops; iforce->bus =IFORCE_232 ; - iforce->serio = serio; -serio_set_drvdata (serio, iforce); + iforce_serio->serio = serio; +serio_set_drvdata (serio, iforce_serio); err =serio_open (serio, drv);if (err)
@@ -191,18 +213,18 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) fail2:serio_close (serio); fail1:serio_set_drvdata (serio,NULL ); -kfree (iforce); +kfree (iforce_serio);return err; }static void iforce_serio_disconnect (struct serio *serio) { -struct iforce *iforce =serio_get_drvdata (serio); +struct iforce_serio *iforce_serio =serio_get_drvdata (serio); -input_unregister_device (iforce->dev); +input_unregister_device (iforce_serio->iforce.dev);serio_close (serio);serio_set_drvdata (serio,NULL ); -kfree (iforce); +kfree (iforce_serio); }static const struct serio_device_id iforce_serio_ids[] = {
drivers/input/joystick/iforce/iforce-usb.c +84 -54
271 lines not on this page · raw message
drivers/input/joystick/iforce/iforce.h +1 -13
@@ -111,19 +111,7 @@ struct iforce {unsigned char data[IFORCE_MAX_LENGTH ];unsigned char edata[IFORCE_MAX_LENGTH ];u16 ecmd; -u16 expect_packet; - -#ifdef CONFIG_JOYSTICK_IFORCE_232 -struct serio *serio;/* RS232 transfer */ -int idx, pkt, len, id; -unsigned char csum; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_USB -struct usb_device *usbdev;/* USB transfer */ -struct usb_interface *intf; -struct urb *irq, *out, *ctrl; -struct usb_ctrlrequest cr; -#endif +spinlock_t xmit_lock;/* Buffer used for asynchronous sending of bytes to the device */ struct circ_buf xmit;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 8/20 Input: iforce - split into core and transport modules
In reply to Dmitry TorokhovNow that we have moved enough transport details into separate source files we can change them into transport modules so that they are only loaded when needed.
--- drivers/input/joystick/iforce/Kconfig | 8 ++--- drivers/input/joystick/iforce/Makefile | 7 ++-- drivers/input/joystick/iforce/iforce-main.c | 35 ++----------------- .../input/joystick/iforce/iforce-packets.c | 2 ++ drivers/input/joystick/iforce/iforce-serio.c | 7 ++++ drivers/input/joystick/iforce/iforce-usb.c | 7 ++++ drivers/input/joystick/iforce/iforce.h | 2 -- 7 files changed, 25 insertions(+), 43 deletions(-)
drivers/input/joystick/iforce/Kconfig +4 -4
@@ -13,15 +13,15 @@ config JOYSTICK_IFORCE module will be called iforce. config JOYSTICK_IFORCE_USB - bool "I-Force USB joysticks and wheels" - depends on JOYSTICK_IFORCE && (JOYSTICK_IFORCE=m || USB=y) && USB + tristate "I-Force USB joysticks and wheels" + depends on JOYSTICK_IFORCE && USB help Say Y here if you have an I-Force joystick or steering wheel connected to your USB port. config JOYSTICK_IFORCE_232 - bool "I-Force Serial joysticks and wheels" - depends on JOYSTICK_IFORCE && (JOYSTICK_IFORCE=m || SERIO=y) && SERIO + tristate "I-Force Serial joysticks and wheels" + depends on JOYSTICK_IFORCE && SERIO help Say Y here if you have an I-Force joystick or steering wheel connected to your serial (COM) port.
drivers/input/joystick/iforce/Makefile +3 -4
@@ -4,8 +4,7 @@ # By Johann Deneux <[email protected]> # -obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o - +obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o iforce-y := iforce-ff.o iforce-main.o iforce-packets.o -iforce-$(CONFIG_JOYSTICK_IFORCE_232) += iforce-serio.o -iforce-$(CONFIG_JOYSTICK_IFORCE_USB) += iforce-usb.o +obj-$(CONFIG_JOYSTICK_IFORCE_232) += iforce-serio.o +obj-$(CONFIG_JOYSTICK_IFORCE_USB) += iforce-usb.o
drivers/input/joystick/iforce/iforce-main.c +2 -33
@@ -24,7 +24,7 @@#include "iforce.h" MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>, Johann Deneux <[email protected]>" ); -MODULE_DESCRIPTION ("USB/RS232 I-Force joysticks and wheels driver" ); +MODULE_DESCRIPTION ("Core I-Force joysticks and wheels driver" );MODULE_LICENSE ("GPL" ); static signed short btn_joystick[] =
@@ -411,35 +411,4 @@ int iforce_init_device(struct device *parent, u16 bustype, fail:input_free_device (input_dev);return error; } - -static int __init iforce_init (void ) -{ -int err =0 ; - -#ifdef CONFIG_JOYSTICK_IFORCE_USB - err =usb_register (&iforce_usb_driver); -if (err) -return err; -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 - err =serio_register_driver (&iforce_serio_drv); -#ifdef CONFIG_JOYSTICK_IFORCE_USB -if (err) -usb_deregister (&iforce_usb_driver); -#endif -#endif -return err; -} - -static void __exit iforce_exit(void) -{ -#ifdef CONFIG_JOYSTICK_IFORCE_USB -usb_deregister (&iforce_usb_driver); -#endif -#ifdef CONFIG_JOYSTICK_IFORCE_232 -serio_unregister_driver (&iforce_serio_drv); -#endif -} - -module_init (iforce_init); -module_exit (iforce_exit); +EXPORT_SYMBOL (iforce_init_device);
drivers/input/joystick/iforce/iforce-packets.c +2 -0
@@ -96,6 +96,7 @@ int iforce_send_packet(struct iforce *iforce, u16 cmd, unsigned char* data)return 0 ; } +EXPORT_SYMBOL (iforce_send_packet);/* Start or stop an effect */ int iforce_control_playback (struct iforce * iforce,u16 id,unsigned int value)
@@ -203,3 +204,4 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)break ; } } +EXPORT_SYMBOL (iforce_process_packet);
drivers/input/joystick/iforce/iforce-serio.c +7 -0
@@ -21,6 +21,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <linux/serio.h> #include "iforce.h" struct iforce_serio {
@@ -250,3 +251,9 @@ struct serio_driver iforce_serio_drv = { .connect = iforce_serio_connect, .disconnect = iforce_serio_disconnect, }; + +module_serio_driver (iforce_serio_drv); + +MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>, Johann Deneux <[email protected]>" ); +MODULE_DESCRIPTION ("RS232 I-Force joysticks and wheels driver" ); +MODULE_LICENSE ("GPL" );
drivers/input/joystick/iforce/iforce-usb.c +7 -0
@@ -21,6 +21,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <linux/usb.h> #include "iforce.h" struct iforce_usb {
@@ -316,3 +317,9 @@ struct usb_driver iforce_usb_driver = { .disconnect = iforce_usb_disconnect, .id_table = iforce_usb_ids, }; + +module_usb_driver (iforce_usb_driver); + +MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>, Johann Deneux <[email protected]>" ); +MODULE_DESCRIPTION ("USB I-Force joysticks and wheels driver" ); +MODULE_LICENSE ("GPL" );
drivers/input/joystick/iforce/iforce.h +0 -2
@@ -26,8 +26,6 @@#include <linux/input.h> #include <linux/module.h> #include <linux/spinlock.h> -#include <linux/usb.h> -#include <linux/serio.h> #include <linux/circ_buf.h> #include <linux/mutex.h>
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 9/20 Input: iforce - use DMA-safe buffer when getting IDs from USB
In reply to Dmitry TorokhovWhen working with USB devices we need to use DMA-safe buffers, and iforce->edata is not one. Let's rework the code to allocate temporary buffer (iforce_get_id() is called only during initialization so there is no reason to have permanent buffer) and use it. While at it, let's utilize usb_control_msg() API which simplifies code.
--- drivers/input/joystick/iforce/iforce-usb.c | 68 +++++++--------------- 1 file changed, 22 insertions(+), 46 deletions(-)
drivers/input/joystick/iforce/iforce-usb.c +22 -46
@@ -29,8 +29,7 @@ struct iforce_usb {struct usb_device *usbdev;struct usb_interface *intf; -struct urb *irq, *out, *ctrl; -struct usb_ctrlrequest cr; +struct urb *irq, *out; };static void __iforce_usb_xmit (struct iforce *iforce)
@@ -92,30 +91,32 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) { struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, iforce); +u8 *buf;int status; - iforce_usb->cr.bRequest = packet[0 ]; - iforce_usb->ctrl->dev = iforce_usb->usbdev; - - status =usb_submit_urb (iforce_usb->ctrl,GFP_KERNEL ); -if (status) { + buf =kmalloc (IFORCE_MAX_LENGTH ,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + status =usb_control_msg (iforce_usb->usbdev, +usb_rcvctrlpipe (iforce_usb->usbdev,0 ), + packet[0 ], +USB_TYPE_VENDOR |USB_DIR_IN | +USB_RECIP_INTERFACE , +0 ,0 , buf,IFORCE_MAX_LENGTH ,HZ ); +if (status <0 ) {dev_err (&iforce_usb->intf->dev, -"usb_submit_urb failed %d\n" , status); -return -EIO ; - } - -wait_event_interruptible_timeout (iforce->wait, - iforce_usb->ctrl->status != -EINPROGRESS ,HZ ); - -if (iforce_usb->ctrl->status) { -dev_dbg (&iforce_usb->intf->dev, -"iforce->ctrl->status = %d\n" , - iforce_usb->ctrl->status); -usb_unlink_urb (iforce_usb->ctrl); -return -EIO ; +"usb_submit_urb failed: %d\n" , status); + }else if (buf[0 ] != packet[0 ]) { + status = -EIO ; + }else { + iforce->ecmd =0xff00 | status; +memcpy (iforce->edata, buf, status); + status =0 ; } -return -(iforce->edata[0 ] != packet[0 ]); +kfree (buf); +return status; }static int iforce_usb_start_io (struct iforce *iforce)
@@ -136,7 +137,6 @@ static void iforce_usb_stop_io(struct iforce *iforce)usb_kill_urb (iforce_usb->irq);usb_kill_urb (iforce_usb->out); -usb_kill_urb (iforce_usb->ctrl); }static const struct iforce_xport_ops iforce_usb_xport_ops = {
@@ -197,18 +197,6 @@ static void iforce_usb_out(struct urb *urb)wake_up (&iforce->wait); } -static void iforce_usb_ctrl (struct urb *urb) -{ -struct iforce_usb *iforce_usb = urb->context; -struct iforce *iforce = &iforce_usb->iforce; - -if (urb->status) -return ; - - iforce->ecmd =0xff00 | urb->actual_length; -wake_up (&iforce->wait); -} -static int iforce_usb_probe (struct usb_interface *intf,const struct usb_device_id *id) {
@@ -236,9 +224,6 @@ static int iforce_usb_probe(struct usb_interface *intf,if (!(iforce_usb->out =usb_alloc_urb (0 ,GFP_KERNEL ))) goto fail; -if (!(iforce_usb->ctrl =usb_alloc_urb (0 ,GFP_KERNEL ))) - goto fail; - iforce = &iforce_usb->iforce; iforce->xport_ops = &iforce_usb_xport_ops;
@@ -247,19 +232,12 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->usbdev = dev; iforce_usb->intf = intf; - iforce_usb->cr.bRequestType =USB_TYPE_VENDOR |USB_DIR_IN |USB_RECIP_INTERFACE ; - iforce_usb->cr.wIndex =0 ; - iforce_usb->cr.wLength =cpu_to_le16 (16 ); -usb_fill_int_urb (iforce_usb->irq, dev,usb_rcvintpipe (dev, epirq->bEndpointAddress), iforce->data,16 , iforce_usb_irq, iforce_usb, epirq->bInterval);usb_fill_int_urb (iforce_usb->out, dev,usb_sndintpipe (dev, epout->bEndpointAddress), iforce_usb +1 ,32 , iforce_usb_out, iforce_usb, epout->bInterval); -usb_fill_control_urb (iforce_usb->ctrl, dev,usb_rcvctrlpipe (dev,0 ), - (void *) &iforce_usb->cr, iforce->edata,16 , iforce_usb_ctrl, iforce_usb); - err =iforce_init_device (&intf->dev,BUS_USB , iforce);if (err) goto fail;
@@ -271,7 +249,6 @@ static int iforce_usb_probe(struct usb_interface *intf,if (iforce_usb) {usb_free_urb (iforce_usb->irq);usb_free_urb (iforce_usb->out); -usb_free_urb (iforce_usb->ctrl);kfree (iforce_usb); }
@@ -288,7 +265,6 @@ static void iforce_usb_disconnect(struct usb_interface *intf)usb_free_urb (iforce_usb->irq);usb_free_urb (iforce_usb->out); -usb_free_urb (iforce_usb->ctrl);kfree (iforce_usb); }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 10/20 Input: iforce - update formatting of switch statements
In reply to Dmitry TorokhovAccording to our coding style case labels in switch statements should be aligned with the switch keyword.
--- drivers/input/joystick/iforce/iforce-ff.c | 18 +-- drivers/input/joystick/iforce/iforce-main.c | 70 +++++------ .../input/joystick/iforce/iforce-packets.c | 112 +++++++++--------- 3 files changed, 100 insertions(+), 100 deletions(-)
drivers/input/joystick/iforce/iforce-ff.c +9 -9
@@ -384,12 +384,12 @@ int iforce_upload_periodic(struct iforce *iforce, struct ff_effect *effect, stru }switch (effect->u.periodic.waveform) { -case FF_SQUARE : wave_code =0x20 ;break ; -case FF_TRIANGLE : wave_code =0x21 ;break ; -case FF_SINE : wave_code =0x22 ;break ; -case FF_SAW_UP : wave_code =0x23 ;break ; -case FF_SAW_DOWN : wave_code =0x24 ;break ; -default : wave_code =0x20 ;break ; +case FF_SQUARE : wave_code =0x20 ;break ; +case FF_TRIANGLE : wave_code =0x21 ;break ; +case FF_SINE : wave_code =0x22 ;break ; +case FF_SAW_UP : wave_code =0x23 ;break ; +case FF_SAW_DOWN : wave_code =0x24 ;break ; +default : wave_code =0x20 ;break ; }if (!old ||need_core (old, effect)) {
@@ -488,9 +488,9 @@ int iforce_upload_condition(struct iforce *iforce, struct ff_effect *effect, strint core_err =0 ;switch (effect->type) { -case FF_SPRING : type =0x40 ;break ; -case FF_DAMPER : type =0x41 ;break ; -default :return -1 ; +case FF_SPRING : type =0x40 ;break ; +case FF_DAMPER : type =0x41 ;break ; +default :return -1 ; }if (!old ||need_condition_modifier (iforce, old, effect)) {
drivers/input/joystick/iforce/iforce-main.c +32 -38
88 lines not on this page · raw message
drivers/input/joystick/iforce/iforce-packets.c +59 -53
125 lines not on this page · raw message
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 11/20 Input: iforce - factor out hat handling when parsing packets
In reply to Dmitry TorokhovThis makes code clearer a bit.
--- .../input/joystick/iforce/iforce-packets.c | 101 ++++++++++-------- 1 file changed, 57 insertions(+), 44 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +57 -44
@@ -130,11 +130,47 @@ 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) +static void iforce_report_hats_buttons (struct iforce *iforce,u8 *data) {struct input_dev *dev = iforce->dev;int i; +input_report_abs (dev,ABS_HAT0X , iforce_hat_to_axis[data[6 ] >>4 ].x); +input_report_abs (dev,ABS_HAT0Y , iforce_hat_to_axis[data[6 ] >>4 ].y); + +for (i =0 ; iforce->type->btn[i] >=0 ; i++) +input_report_key (dev, iforce->type->btn[i], + data[(i >>3 ) +5 ] & (1 << (i &7 ))); + +/* If there are untouched bits left, interpret them as the second hat */ +if (i <=8 ) { +u8 btns = data[6 ]; + +if (test_bit (ABS_HAT1X , dev->absbit)) { +if (btns &BIT (3 )) +input_report_abs (dev,ABS_HAT1X ,-1 ); +else if (btns &BIT (1 )) +input_report_abs (dev,ABS_HAT1X ,1 ); +else +input_report_abs (dev,ABS_HAT1X ,0 ); + } + +if (test_bit (ABS_HAT1Y , dev->absbit)) { +if (btns &BIT (0 )) +input_report_abs (dev,ABS_HAT1Y ,-1 ); +else if (btns &BIT (2 )) +input_report_abs (dev,ABS_HAT1Y ,1 ); +else +input_report_abs (dev,ABS_HAT1Y ,0 ); + } + } +} + +void iforce_process_packet (struct iforce *iforce,u16 cmd,unsigned char *data) +{ +struct input_dev *dev = iforce->dev; +int i, j; +wake_up (&iforce->wait);if (!iforce->type)
@@ -143,48 +179,26 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)switch (HI (cmd)) {case 0x01 :/* joystick position data */ -case 0x03 :/* wheel position data */ -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 ])); -input_report_abs (dev,ABS_THROTTLE ,255 - data[4 ]); -if (LO (cmd) >=8 &&test_bit (ABS_RUDDER ,dev->absbit)) -input_report_abs (dev,ABS_RUDDER , (__s8 )data[7 ]); - }else { -input_report_abs (dev,ABS_WHEEL , (__s16) (((__s16 )data[1 ] <<8 ) | data[0 ])); -input_report_abs (dev,ABS_GAS ,255 - data[2 ]); -input_report_abs (dev,ABS_BRAKE ,255 - data[3 ]); - } +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 ])); +input_report_abs (dev,ABS_THROTTLE ,255 - data[4 ]); -input_report_abs (dev,ABS_HAT0X , iforce_hat_to_axis[data[6 ] >>4 ].x); -input_report_abs (dev,ABS_HAT0Y , iforce_hat_to_axis[data[6 ] >>4 ].y); - -for (i =0 ; iforce->type->btn[i] >=0 ; i++) -input_report_key (dev, iforce->type->btn[i], data[(i >>3 ) +5 ] & (1 << (i &7 ))); - -/* If there are untouched bits left, interpret them as the second hat */ -if (i <=8 ) { -int btns = data[6 ]; -if (test_bit (ABS_HAT1X , dev->absbit)) { -if (btns &8 ) -input_report_abs (dev,ABS_HAT1X ,-1 ); -else if (btns &2 ) -input_report_abs (dev,ABS_HAT1X ,1 ); -else -input_report_abs (dev,ABS_HAT1X ,0 ); - } -if (test_bit (ABS_HAT1Y , dev->absbit)) { -if (btns &1 ) -input_report_abs (dev,ABS_HAT1Y ,-1 ); -else if (btns &4 ) -input_report_abs (dev,ABS_HAT1Y ,1 ); -else -input_report_abs (dev,ABS_HAT1Y ,0 ); - } - } +if (LO (cmd) >=8 &&test_bit (ABS_RUDDER ,dev->absbit)) +input_report_abs (dev,ABS_RUDDER , (__s8 )data[7 ]); + +iforce_report_hats_buttons (iforce, data);input_sync (dev); +break ; +case 0x03 :/* wheel position data */ +input_report_abs (dev,ABS_WHEEL , (__s16) (((__s16 )data[1 ] <<8 ) | data[0 ])); +input_report_abs (dev,ABS_GAS ,255 - data[2 ]); +input_report_abs (dev,ABS_BRAKE ,255 - data[3 ]); + +iforce_report_hats_buttons (iforce, data); + +input_sync (dev);break ;case 0x02 :/* status report */
@@ -202,11 +216,10 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)/* 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 ) -mark_core_as_ready (iforce, data[j] | (data[j+1 ]<<8 )); - } + +for (j =3 ; j <LO (cmd); j +=2 ) +mark_core_as_ready (iforce, data[j] | (data[j +1 ] <<8 )); +break ; } }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 12/20 Input: iforce - do not combine arguments for iforce_process_packet()
In reply to Dmitry TorokhovCurrent code combines packet type and data length into single argument to iforce_process_packet() and then has to untangle it. It is much clearer to simply use separate arguments.
--- drivers/input/joystick/iforce/iforce-packets.c | 9 +++++---- drivers/input/joystick/iforce/iforce-serio.c | 8 ++++---- drivers/input/joystick/iforce/iforce-usb.c | 4 ++-- drivers/input/joystick/iforce/iforce.h | 3 ++- 4 files changed, 13 insertions(+), 11 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +5 -4
@@ -166,7 +166,8 @@ static void iforce_report_hats_buttons(struct iforce *iforce, u8 *data) } } -void iforce_process_packet (struct iforce *iforce,u16 cmd,unsigned char *data) +void iforce_process_packet (struct iforce *iforce, +u8 packet_id,u8 *data,size_t len) {struct input_dev *dev = iforce->dev;int i, j;
@@ -176,14 +177,14 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)if (!iforce->type)return ; -switch (HI (cmd)) { +switch (packet_id) {case 0x01 :/* joystick position data */ 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 ]));input_report_abs (dev,ABS_THROTTLE ,255 - data[4 ]); -if (LO (cmd) >=8 &&test_bit (ABS_RUDDER ,dev->absbit)) +if (len >=8 &&test_bit (ABS_RUDDER ,dev->absbit))input_report_abs (dev,ABS_RUDDER , (__s8 )data[7 ]);iforce_report_hats_buttons (iforce, data);
@@ -217,7 +218,7 @@ void iforce_process_packet(struct iforce *iforce, u16 cmd, unsigned char *data)input_report_ff_status (dev, i,FF_STATUS_STOPPED ); } -for (j =3 ; j <LO (cmd); j +=2 ) +for (j =3 ; j < len; j +=2 )mark_core_as_ready (iforce, data[j] | (data[j +1 ] <<8 ));break ;
drivers/input/joystick/iforce/iforce-serio.c +4 -4
@@ -163,16 +163,16 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, }if (iforce_serio->idx == iforce_serio->len) { -u16 cmd = (iforce_serio->id <<8 ) | iforce_serio->idx; -/* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet =0 ; - iforce->ecmd = cmd; + iforce->ecmd = (iforce_serio->id <<8 ) | + iforce_serio->idx;memcpy (iforce->edata, iforce->data,IFORCE_MAX_LENGTH ); } -iforce_process_packet (iforce, cmd, iforce->data); +iforce_process_packet (iforce, iforce_serio->id, + iforce->data, iforce_serio->len); iforce_serio->pkt =0 ; iforce_serio->id =0 ;
drivers/input/joystick/iforce/iforce-usb.c +2 -2
@@ -170,8 +170,8 @@ static void iforce_usb_irq(struct urb *urb) goto exit; } -iforce_process_packet (iforce, - (iforce->data[0 ] <<8 ) | (urb->actual_length -1 ), iforce->data +1 ); +iforce_process_packet (iforce, iforce->data[0 ], + iforce->data +1 , urb->actual_length -1 ); exit: status =usb_submit_urb (urb,GFP_ATOMIC );
drivers/input/joystick/iforce/iforce.h +2 -1
@@ -147,7 +147,8 @@ int iforce_init_device(struct device *parent, u16 bustype,/* iforce-packets.c */ int iforce_control_playback (struct iforce *,u16 id,unsigned int ); -void iforce_process_packet (struct iforce *iforce,u16 cmd,unsigned char *data); +void iforce_process_packet (struct iforce *iforce, +u8 packet_id,u8 *data,size_t len);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);
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 13/20 Input: iforce - signal command completion from transport code
In reply to Dmitry TorokhovSignalling command completion from iforce_process_packet() does not make sense, as not all transport use the same data path for both commands and motion data form the device, that is why USB code already has to signal command completion iforce_usb_out().
Let's move signalling completion into individual transport modules.
--- drivers/input/joystick/iforce/iforce-packets.c | 2 -- drivers/input/joystick/iforce/iforce-serio.c | 9 ++++++--- 2 files changed, 6 insertions(+), 5 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +0 -2
@@ -172,8 +172,6 @@ void iforce_process_packet(struct iforce *iforce,struct input_dev *dev = iforce->dev;int i, j; -wake_up (&iforce->wait); -if (!iforce->type)return ;
drivers/input/joystick/iforce/iforce-serio.c +6 -3
@@ -169,10 +169,13 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, iforce->ecmd = (iforce_serio->id <<8 ) | iforce_serio->idx;memcpy (iforce->edata, iforce->data,IFORCE_MAX_LENGTH ); - } -iforce_process_packet (iforce, iforce_serio->id, - iforce->data, iforce_serio->len); +/* Signal that command is done */ +wake_up (&iforce->wait); + }else { +iforce_process_packet (iforce, iforce_serio->id, + iforce->data, iforce_serio->len); + } iforce_serio->pkt =0 ; iforce_serio->id =0 ;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 14/20 Input: iforce - only call iforce_process_packet() if initialized
In reply to Dmitry TorokhovIt is excessive to check if device is fully initialized in iforce_process_packet(), as for USB-conected devices we do not start collecting reports until the device is fully initialized.
Let's change serio transport code to not call iforce_process_packet() until device initialization is done.
--- drivers/input/joystick/iforce/iforce-packets.c | 3 --- drivers/input/joystick/iforce/iforce-serio.c | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-)
drivers/input/joystick/iforce/iforce-packets.c +0 -3
@@ -172,9 +172,6 @@ void iforce_process_packet(struct iforce *iforce,struct input_dev *dev = iforce->dev;int i, j; -if (!iforce->type) -return ; -switch (packet_id) {case 0x01 :/* joystick position data */
drivers/input/joystick/iforce/iforce-serio.c +1 -1
@@ -172,7 +172,7 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,/* Signal that command is done */ wake_up (&iforce->wait); - }else { + }else if (likely (iforce->type)) {iforce_process_packet (iforce, iforce_serio->id, iforce->data, iforce_serio->len); }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 15/20 Input: iforce - allow callers supply data buffer when fetching device IDs
In reply to Dmitry TorokhovWe want to move buffer handling into transport layers as the properties of buffers (DMA-safety, alignment, etc) are different for different transports. To allow this, let's allow caller to specify their own buffers for the results of iforce_get_id_packet() and let transport drivers to figure what buffers they need to use for transfers.
--- drivers/input/joystick/iforce/iforce-main.c | 27 ++++++++++--------- drivers/input/joystick/iforce/iforce-serio.c | 28 ++++++++++++++------ drivers/input/joystick/iforce/iforce-usb.c | 11 ++++---- drivers/input/joystick/iforce/iforce.h | 11 ++++---- 4 files changed, 47 insertions(+), 30 deletions(-)
drivers/input/joystick/iforce/iforce-main.c +15 -12
@@ -225,7 +225,9 @@ int iforce_init_device(struct device *parent, u16 bustype, {struct input_dev *input_dev;struct ff_device *ff; -unsigned char c[] ="CEOV" ; +u8 c[] ="CEOV" ; +u8 buf[IFORCE_MAX_LENGTH ]; +size_t len;int i, error;int ff_effects =0 ;
@@ -269,7 +271,7 @@ int iforce_init_device(struct device *parent, u16 bustype,*/ for (i =0 ; i <20 ; i++) -if (!iforce_get_id_packet (iforce,"O" )) +if (!iforce_get_id_packet (iforce,'O' , buf, &len))break ;if (i ==20 ) {/* 5 seconds */
@@ -283,23 +285,23 @@ int iforce_init_device(struct device *parent, u16 bustype,* Get device info. */ -if (!iforce_get_id_packet (iforce,"M" )) - input_dev->id.vendor = (iforce->edata[2 ] <<8 ) | iforce->edata[1 ]; +if (!iforce_get_id_packet (iforce,'M' , buf, &len) || len <3 ) + input_dev->id.vendor = (buf[2 ] <<8 ) | buf[1 ];else dev_warn (&iforce->dev->dev,"Device does not respond to id packet M\n" ); -if (!iforce_get_id_packet (iforce,"P" )) - input_dev->id.product = (iforce->edata[2 ] <<8 ) | iforce->edata[1 ]; +if (!iforce_get_id_packet (iforce,'P' , buf, &len) || len <3 ) + input_dev->id.product = (buf[2 ] <<8 ) | buf[1 ];else dev_warn (&iforce->dev->dev,"Device does not respond to id packet P\n" ); -if (!iforce_get_id_packet (iforce,"B" )) - iforce->device_memory.end = (iforce->edata[2 ] <<8 ) | iforce->edata[1 ]; +if (!iforce_get_id_packet (iforce,'B' , buf, &len) || len <3 ) + iforce->device_memory.end = (buf[2 ] <<8 ) | buf[1 ];else dev_warn (&iforce->dev->dev,"Device does not respond to id packet B\n" ); -if (!iforce_get_id_packet (iforce,"N" )) - ff_effects = iforce->edata[1 ]; +if (!iforce_get_id_packet (iforce,'N' , buf, &len) || len <2 ) + ff_effects = buf[1 ];else dev_warn (&iforce->dev->dev,"Device does not respond to id packet N\n" );
@@ -315,8 +317,9 @@ int iforce_init_device(struct device *parent, u16 bustype,*/ for (i =0 ; c[i]; i++) -if (!iforce_get_id_packet (iforce, c + i)) -iforce_dump_packet (iforce,"info" , iforce->ecmd, iforce->edata); +if (!iforce_get_id_packet (iforce, c[i], buf, &len)) +iforce_dump_packet (iforce,"info" , + (FF_CMD_QUERY &0xff00 ) | len, buf);/* * Disable spring, enable force feedback.
drivers/input/joystick/iforce/iforce-serio.c +20 -8
@@ -31,6 +31,8 @@ struct iforce_serio {int idx, pkt, len, id;u8 csum;u8 expect_packet; +u8 cmd_response[IFORCE_MAX_LENGTH ]; +u8 cmd_response_len; };static void iforce_serio_xmit (struct iforce *iforce)
@@ -81,24 +83,34 @@ 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) +static int iforce_serio_get_id (struct iforce *iforce,u8 id, +u8 *response_data,size_t *response_len) {struct iforce_serio *iforce_serio =container_of (iforce, struct iforce_serio, iforce); iforce_serio->expect_packet =HI (FF_CMD_QUERY ); -iforce_send_packet (iforce,FF_CMD_QUERY , packet); + iforce_serio->cmd_response_len =0 ; + +iforce_send_packet (iforce,FF_CMD_QUERY , &id);wait_event_interruptible_timeout (iforce->wait, !iforce_serio->expect_packet,HZ );if (iforce_serio->expect_packet) { iforce_serio->expect_packet =0 ; -return -EIO ; +return -ETIMEDOUT ; } -return -(iforce->edata[0 ] != packet[0 ]); +if (iforce_serio->cmd_response[0 ] != id) +return -EIO ; + +memcpy (response_data, iforce_serio->cmd_response, + iforce_serio->cmd_response_len); + *response_len = iforce_serio->cmd_response_len; + +return 0 ; }static int iforce_serio_start_io (struct iforce *iforce)
@@ -127,7 +139,7 @@ static void iforce_serio_write_wakeup(struct serio *serio) }static irqreturn_t iforce_serio_irq (struct serio *serio, -unsigned char data,unsigned int flags) +unsigned char data,unsigned int flags) {struct iforce_serio *iforce_serio =serio_get_drvdata (serio);struct iforce *iforce = &iforce_serio->iforce;
@@ -166,9 +178,9 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,/* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet =0 ; - iforce->ecmd = (iforce_serio->id <<8 ) | - iforce_serio->idx; -memcpy (iforce->edata, iforce->data,IFORCE_MAX_LENGTH ); +memcpy (iforce_serio->cmd_response, iforce->data, +IFORCE_MAX_LENGTH ); + iforce_serio->cmd_response_len = iforce_serio->len;/* Signal that command is done */ wake_up (&iforce->wait);
drivers/input/joystick/iforce/iforce-usb.c +6 -5
@@ -87,7 +87,8 @@ static void iforce_usb_xmit(struct iforce *iforce)__iforce_usb_xmit (iforce); } -static int iforce_usb_get_id (struct iforce *iforce,u8 *packet) +static int iforce_usb_get_id (struct iforce *iforce,u8 id, +u8 *response_data,size_t *response_len) { struct iforce_usb *iforce_usb = container_of(iforce, struct iforce_usb, iforce);
@@ -100,18 +101,18 @@ static int iforce_usb_get_id(struct iforce *iforce, u8 *packet) status =usb_control_msg (iforce_usb->usbdev,usb_rcvctrlpipe (iforce_usb->usbdev,0 ), - packet[0 ], + id,USB_TYPE_VENDOR |USB_DIR_IN |USB_RECIP_INTERFACE ,0 ,0 , buf,IFORCE_MAX_LENGTH ,HZ );if (status <0 ) {dev_err (&iforce_usb->intf->dev,"usb_submit_urb failed: %d\n" , status); - }else if (buf[0 ] != packet[0 ]) { + }else if (buf[0 ] != id) { status = -EIO ; }else { - iforce->ecmd =0xff00 | status; -memcpy (iforce->edata, buf, status); +memcpy (response_data, buf, status); + *response_len = status; status =0 ; }
drivers/input/joystick/iforce/iforce.h +6 -5
@@ -95,7 +95,8 @@ struct iforce;struct iforce_xport_ops {void (*xmit)(struct iforce *iforce); -int (*get_id)(struct iforce *iforce,u8 * id); +int (*get_id)(struct iforce *iforce,u8 id, +u8 *response_data,size_t *response_len);int (*start_io)(struct iforce *iforce);void (*stop_io)(struct iforce *iforce); };
@@ -107,8 +108,6 @@ struct iforce {int bus;unsigned char data[IFORCE_MAX_LENGTH ]; -unsigned char edata[IFORCE_MAX_LENGTH ]; -u16 ecmd;spinlock_t xmit_lock;/* Buffer used for asynchronous sending of bytes to the device */
@@ -135,9 +134,11 @@ struct iforce {/* Encode a time value */ #define TIME_SCALE (a) (a) -static inline int iforce_get_id_packet (struct iforce *iforce,u8 * id) +static inline int iforce_get_id_packet (struct iforce *iforce,u8 id, +u8 *response_data,size_t *response_len) { -return iforce->xport_ops->get_id (iforce, id); +return iforce->xport_ops->get_id (iforce, id, + response_data, response_len); }/* Public functions */
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 16/20 Input: iforce - use DMA-safe buffores for USB transfers
In reply to Dmitry TorokhovUSB transport has to use cache line-aligned buffers for transfers to avoid DMA issues; serio doe snot have such restrictions. Let's move "data_in" buffer from main driver structure into transport modules and make sure USB requirements are respected.
--- drivers/input/joystick/iforce/iforce-serio.c | 10 ++++--- drivers/input/joystick/iforce/iforce-usb.c | 28 +++++++++++++------- drivers/input/joystick/iforce/iforce.h | 2 -- 3 files changed, 25 insertions(+), 15 deletions(-)
drivers/input/joystick/iforce/iforce-serio.c +6 -4
@@ -33,6 +33,7 @@ struct iforce_serio {u8 expect_packet;u8 cmd_response[IFORCE_MAX_LENGTH ];u8 cmd_response_len; +u8 data_in[IFORCE_MAX_LENGTH ]; };static void iforce_serio_xmit (struct iforce *iforce)
@@ -169,7 +170,7 @@ static irqreturn_t iforce_serio_irq(struct serio *serio, }if (iforce_serio->idx < iforce_serio->len) { - iforce->data[iforce_serio->idx++] = data; + iforce_serio->data_in[iforce_serio->idx++] = data; iforce_serio->csum += data; goto out; }
@@ -178,15 +179,16 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,/* Handle command completion */ if (iforce_serio->expect_packet == iforce_serio->id) { iforce_serio->expect_packet =0 ; -memcpy (iforce_serio->cmd_response, iforce->data, -IFORCE_MAX_LENGTH ); +memcpy (iforce_serio->cmd_response, + iforce_serio->data_in,IFORCE_MAX_LENGTH ); iforce_serio->cmd_response_len = iforce_serio->len;/* Signal that command is done */ wake_up (&iforce->wait); }else if (likely (iforce->type)) {iforce_process_packet (iforce, iforce_serio->id, - iforce->data, iforce_serio->len); + iforce_serio->data_in, + iforce_serio->len); } iforce_serio->pkt =0 ;
drivers/input/joystick/iforce/iforce-usb.c +19 -9
@@ -30,6 +30,9 @@ struct iforce_usb {struct usb_device *usbdev;struct usb_interface *intf;struct urb *irq, *out; + +u8 data_in[IFORCE_MAX_LENGTH ]____cacheline_aligned ; +u8 data_out[IFORCE_MAX_LENGTH ]____cacheline_aligned ; };static void __iforce_usb_xmit (struct iforce *iforce)
@@ -171,8 +174,8 @@ static void iforce_usb_irq(struct urb *urb) goto exit; } -iforce_process_packet (iforce, iforce->data[0 ], - iforce->data +1 , urb->actual_length -1 ); +iforce_process_packet (iforce, iforce_usb->data_in[0 ], + iforce_usb->data_in +1 , urb->actual_length -1 ); exit: status =usb_submit_urb (urb,GFP_ATOMIC );
@@ -216,13 +219,16 @@ static int iforce_usb_probe(struct usb_interface *intf, epirq = &interface->endpoint[0 ].desc; epout = &interface->endpoint[1 ].desc; -if (!(iforce_usb =kzalloc (sizeof (*iforce_usb) +32 ,GFP_KERNEL ))) + iforce_usb =kzalloc (sizeof (*iforce_usb),GFP_KERNEL ); +if (!iforce_usb) goto fail; -if (!(iforce_usb->irq =usb_alloc_urb (0 ,GFP_KERNEL ))) + iforce_usb->irq =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!iforce_usb->irq) goto fail; -if (!(iforce_usb->out =usb_alloc_urb (0 ,GFP_KERNEL ))) + iforce_usb->out =usb_alloc_urb (0 ,GFP_KERNEL ); +if (!iforce_usb->out) goto fail; iforce = &iforce_usb->iforce;
@@ -233,11 +239,15 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->usbdev = dev; iforce_usb->intf = intf; -usb_fill_int_urb (iforce_usb->irq, dev,usb_rcvintpipe (dev, epirq->bEndpointAddress), - iforce->data,16 , iforce_usb_irq, iforce_usb, epirq->bInterval); +usb_fill_int_urb (iforce_usb->irq, dev, +usb_rcvintpipe (dev, epirq->bEndpointAddress), + iforce_usb->data_in,sizeof (iforce_usb->data_in), + iforce_usb_irq, iforce_usb, epirq->bInterval); -usb_fill_int_urb (iforce_usb->out, dev,usb_sndintpipe (dev, epout->bEndpointAddress), - iforce_usb +1 ,32 , iforce_usb_out, iforce_usb, epout->bInterval); +usb_fill_int_urb (iforce_usb->out, dev, +usb_sndintpipe (dev, epout->bEndpointAddress), + iforce_usb->data_out,sizeof (iforce_usb->data_out), + iforce_usb_out, iforce_usb, epout->bInterval); err =iforce_init_device (&intf->dev,BUS_USB , iforce);if (err)
drivers/input/joystick/iforce/iforce.h +0 -2
@@ -107,8 +107,6 @@ struct iforce {const struct iforce_xport_ops *xport_ops;int bus; -unsigned char data[IFORCE_MAX_LENGTH ]; -spinlock_t xmit_lock;/* Buffer used for asynchronous sending of bytes to the device */ struct circ_buf xmit;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 17/20 Input: only credit entropy when events are generated by a device
In reply to Dmitry TorokhovCurrently we credit entropy (via add_input_randomness()) regardless of where an event comes form, a device itself, or an input handler, such as evdev (and thus from userspace). While access to event devices is supposed to be tightly controlled (one does not want random processes to be able to observe or inject keystrokes), developers may use evdev to inject events for testing purposes. Let's make sure that such events to not contribute to the entropy to keep the pool 'pure' and do not expose developer's boxes to not so random data.
--- drivers/input/input.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
drivers/input/input.c +7 -4
@@ -368,12 +368,15 @@ static int input_get_disposition(struct input_dev *dev, }static void input_handle_event (struct input_dev *dev, -unsigned int type,unsigned int code,int value) +unsigned int type,unsigned int code,int value, +bool can_credit_entropy) {int disposition =input_get_disposition (dev, type, code, &value); -if (disposition !=INPUT_IGNORE_EVENT && type !=EV_SYN ) +if (can_credit_entropy && + disposition !=INPUT_IGNORE_EVENT && type !=EV_SYN ) {add_input_randomness (type, code, value); + }if ((disposition &INPUT_PASS_TO_DEVICE ) && dev->event) dev->event (dev, type, code, value);
@@ -434,7 +437,7 @@ void input_event(struct input_dev *dev,if (is_event_supported (type, dev->evbit,EV_MAX )) {spin_lock_irqsave (&dev->event_lock, flags); -input_handle_event (dev, type, code, value); +input_handle_event (dev, type, code, value, true);spin_unlock_irqrestore (&dev->event_lock, flags); } }
@@ -464,7 +467,7 @@ void input_inject_event(struct input_handle *handle,rcu_read_lock (); grab =rcu_dereference (dev->grab);if (!grab || grab == handle) -input_handle_event (dev, type, code, value); +input_handle_event (dev, type, code, value, false);rcu_read_unlock ();spin_unlock_irqrestore (&dev->event_lock, flags);
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 18/20 Input: iforce - drop bus type from iforce structure
In reply to Dmitry TorokhovIt is not needed anymore as behavior is controlled by the transport operations set up for given device.
--- drivers/input/joystick/iforce/iforce-serio.c | 1 - drivers/input/joystick/iforce/iforce-usb.c | 1 - drivers/input/joystick/iforce/iforce.h | 5 ----- 3 files changed, 7 deletions(-)
drivers/input/joystick/iforce/iforce-serio.c +0 -1
@@ -214,7 +214,6 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv) iforce = &iforce_serio->iforce; iforce->xport_ops = &iforce_serio_xport_ops; - iforce->bus =IFORCE_232 ; iforce_serio->serio = serio;serio_set_drvdata (serio, iforce_serio);
drivers/input/joystick/iforce/iforce-usb.c +0 -1
@@ -234,7 +234,6 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce = &iforce_usb->iforce; iforce->xport_ops = &iforce_usb_xport_ops; - iforce->bus =IFORCE_USB ; iforce_usb->usbdev = dev; iforce_usb->intf = intf;
drivers/input/joystick/iforce/iforce.h +0 -5
@@ -38,10 +38,6 @@#define IFORCE_MAX_LENGTH 16 -/* iforce::bus */ -#define IFORCE_232 1 -#define IFORCE_USB 2 -#define IFORCE_EFFECTS_MAX 32/* Each force feedback effect is made of one core effect, which can be
@@ -105,7 +101,6 @@ struct iforce {struct input_dev *dev;/* Input device interface */ struct iforce_device *type;const struct iforce_xport_ops *xport_ops; -int bus;spinlock_t xmit_lock;/* Buffer used for asynchronous sending of bytes to the device */
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 19/20 Input: iforce - drop couple of temps from transport code
In reply to Dmitry TorokhovTransport initialization code now deals mostly with transport-specific data, so we can drop couple of temporary variables.
--- drivers/input/joystick/iforce/iforce-serio.c | 7 ++----- drivers/input/joystick/iforce/iforce-usb.c | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-)
drivers/input/joystick/iforce/iforce-serio.c +2 -5
@@ -204,16 +204,13 @@ static irqreturn_t iforce_serio_irq(struct serio *serio,static int iforce_serio_connect (struct serio *serio,struct serio_driver *drv) {struct iforce_serio *iforce_serio; -struct iforce *iforce;int err; iforce_serio =kzalloc (sizeof (*iforce_serio),GFP_KERNEL );if (!iforce_serio)return -ENOMEM ; - iforce = &iforce_serio->iforce; - - iforce->xport_ops = &iforce_serio_xport_ops; + iforce_serio->iforce.xport_ops = &iforce_serio_xport_ops; iforce_serio->serio = serio;serio_set_drvdata (serio, iforce_serio);
@@ -222,7 +219,7 @@ static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)if (err) goto fail1; - err =iforce_init_device (&serio->dev,BUS_RS232 , iforce); + err =iforce_init_device (&serio->dev,BUS_RS232 , &iforce_serio->iforce);if (err) goto fail2;
drivers/input/joystick/iforce/iforce-usb.c +2 -5
@@ -208,7 +208,6 @@ static int iforce_usb_probe(struct usb_interface *intf,struct usb_host_interface *interface;struct usb_endpoint_descriptor *epirq, *epout;struct iforce_usb *iforce_usb; -struct iforce *iforce;int err = -ENOMEM ; interface = intf->cur_altsetting;
@@ -231,9 +230,7 @@ static int iforce_usb_probe(struct usb_interface *intf,if (!iforce_usb->out) goto fail; - iforce = &iforce_usb->iforce; - - iforce->xport_ops = &iforce_usb_xport_ops; + iforce_usb->iforce.xport_ops = &iforce_usb_xport_ops; iforce_usb->usbdev = dev; iforce_usb->intf = intf;
@@ -248,7 +245,7 @@ static int iforce_usb_probe(struct usb_interface *intf, iforce_usb->data_out,sizeof (iforce_usb->data_out), iforce_usb_out, iforce_usb, epout->bInterval); - err =iforce_init_device (&intf->dev,BUS_USB , iforce); + err =iforce_init_device (&intf->dev,BUS_USB , &iforce_usb->iforce);if (err) goto fail;
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Dmitry Torokhov
maintainerPATCH 20/20 Input: iforce - use unaligned accessors, where appropriate
In reply to Dmitry TorokhovInstead of open-coding conversion from/to little-endian, let's use proper accessors.
--- drivers/input/joystick/iforce/iforce-main.c | 7 ++++--- drivers/input/joystick/iforce/iforce-packets.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/input/joystick/iforce/iforce-main.c +4 -3
@@ -21,6 +21,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <asm/unaligned.h> #include "iforce.h" MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>, Johann Deneux <[email protected]>" );
@@ -286,17 +287,17 @@ int iforce_init_device(struct device *parent, u16 bustype,*/ if (!iforce_get_id_packet (iforce,'M' , buf, &len) || len <3 ) - input_dev->id.vendor = (buf[2 ] <<8 ) | buf[1 ]; + input_dev->id.vendor =get_unaligned_le16 (buf +1 );else dev_warn (&iforce->dev->dev,"Device does not respond to id packet M\n" );if (!iforce_get_id_packet (iforce,'P' , buf, &len) || len <3 ) - input_dev->id.product = (buf[2 ] <<8 ) | buf[1 ]; + input_dev->id.product =get_unaligned_le16 (buf +1 );else dev_warn (&iforce->dev->dev,"Device does not respond to id packet P\n" );if (!iforce_get_id_packet (iforce,'B' , buf, &len) || len <3 ) - iforce->device_memory.end = (buf[2 ] <<8 ) | buf[1 ]; + iforce->device_memory.end =get_unaligned_le16 (buf +1 );else dev_warn (&iforce->dev->dev,"Device does not respond to id packet B\n" );
drivers/input/joystick/iforce/iforce-packets.c +8 -4
@@ -21,6 +21,7 @@* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include <asm/unaligned.h> #include "iforce.h" static struct {
@@ -175,8 +176,10 @@ void iforce_process_packet(struct iforce *iforce,switch (packet_id) {case 0x01 :/* joystick position data */ -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 ])); +input_report_abs (dev,ABS_X , + (__s16 )get_unaligned_le16 (data)); +input_report_abs (dev,ABS_Y , + (__s16 )get_unaligned_le16 (data +2 ));input_report_abs (dev,ABS_THROTTLE ,255 - data[4 ]);if (len >=8 &&test_bit (ABS_RUDDER ,dev->absbit))
@@ -188,7 +191,8 @@ void iforce_process_packet(struct iforce *iforce,break ;case 0x03 :/* wheel position data */ -input_report_abs (dev,ABS_WHEEL , (__s16) (((__s16 )data[1 ] <<8 ) | data[0 ])); +input_report_abs (dev,ABS_WHEEL , + (__s16 )get_unaligned_le16 (data));input_report_abs (dev,ABS_GAS ,255 - data[2 ]);input_report_abs (dev,ABS_BRAKE ,255 - data[3 ]);
@@ -214,7 +218,7 @@ void iforce_process_packet(struct iforce *iforce, }for (j =3 ; j < len; j +=2 ) -mark_core_as_ready (iforce, data[j] | (data[j +1 ] <<8 )); +mark_core_as_ready (iforce,get_unaligned_le16 (data + j));break ; }
Signature · 1 line
2.19.0.397.gdd90340f6a-goog
Quoted 6 lines · Dmitry Torokhov
The kernel is supposed to handle multiple devices, static flags in packet handling code will never work.
Signed-off-by Dmitry Torokhov <[email protected]>---
Quoted 8 lines
This is a random assortment of iforce patches that I made a few weeks back.
Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome).
Thanks!
Hello Dmitry,
I tested those patches and I didn't find any obvious issues. The basic functions do work (i.e. buttons and axes, don't have a HAT so I can't test that), force feedback seems to work to the extent it was before (I only have fftest though, no games that support force feedback). I'll go through a few more applications and see if anything not obvious is broken.
Unfortunately, I only have that one wheel and I can only test USB connections at the moment (unless I find a proper serial adaptor, but I'm not sure if that would even work).
Are those patches planned to go into 4.19 or are they intended to be merged in the next development cycle?
Dmitry Torokhov
maintainerQuoted 15 lines · Tim Schumacher
Quoted 6 lines · Dmitry Torokhov
The kernel is supposed to handle multiple devices, static flags in packet handling code will never work.
Signed-off-by Dmitry Torokhov <[email protected]>---
Quoted 8 lines
This is a random assortment of iforce patches that I made a few weeks back.
Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome).
Thanks!
Quoted 8 lines
Hello Dmitry,
I tested those patches and I didn't find any obvious issues. The basic functions do work (i.e. buttons and axes, don't have a HAT so I can't test that), force feedback seems to work to the extent it was before (I only have fftest though, no games that support force feedback). I'll go through a few more applications and see if anything not obvious is broken.
Thank you for taking a look.
Quoted 6 lines
Unfortunately, I only have that one wheel and I can only test USB connections at the moment (unless I find a proper serial adaptor, but I'm not sure if that would even work).
Are those patches planned to go into 4.19 or are they intended to be merged in the next development cycle?
Definitely not 4.19. Could be 4.20 or 4.21...
Thanks.
Signature · 1 line
Dmitry
Quoted 31 lines · Dmitry Torokhov
Quoted 15 lines · Tim Schumacher
Quoted 6 lines · Dmitry Torokhov
The kernel is supposed to handle multiple devices, static flags in packet handling code will never work.
Signed-off-by Dmitry Torokhov <[email protected]>---
Quoted 8 lines
This is a random assortment of iforce patches that I made a few weeks back.
Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome).
Thanks!
Quoted 8 lines
Hello Dmitry,
I tested those patches and I didn't find any obvious issues. The basic functions do work (i.e. buttons and axes, don't have a HAT so I can't test that), force feedback seems to work to the extent it was before (I only have fftest though, no games that support force feedback). I'll go through a few more applications and see if anything not obvious is broken.
Thank you for taking a look.
Quoted 4 lines
Unfortunately, I only have that one wheel and I can only test USB connections at the moment (unless I find a proper serial adaptor, but I'm not sure if that would even work).
Quoted 7 lines
Quoted 2 lines
Are those patches planned to go into 4.19 or are they intended to be merged in the next development cycle?
Definitely not 4.19. Could be 4.20 or 4.21...
Thanks.
Hello Dmitry,
as a followup to the last E-Mail I sent about this topic, the complete chain of patches has been in my personal tree since September of 2018 and there have been no issues so far as well. I tested a few more games and utilities, and I was able to test with multiple wheels simultaneously as well.
In the end it's still your decision, but imo those patches should be fine to pull in.
Tim
Dmitry Torokhov
maintainerQuoted 40 lines · Tim Schumacher
Quoted 31 lines · Dmitry Torokhov
Quoted 15 lines · Tim Schumacher
Quoted 6 lines · Dmitry Torokhov
The kernel is supposed to handle multiple devices, static flags in packet handling code will never work.
Signed-off-by Dmitry Torokhov <[email protected]>---
Quoted 8 lines
This is a random assortment of iforce patches that I made a few weeks back.
Tim, I do not have hardware, so I was bound to screw it up, but if you have some time I'd appreciate if you try them out (and if I indeed broke things if you could identify issues that would be even more awesome).
Thanks!
Quoted 8 lines
Hello Dmitry,
I tested those patches and I didn't find any obvious issues. The basic functions do work (i.e. buttons and axes, don't have a HAT so I can't test that), force feedback seems to work to the extent it was before (I only have fftest though, no games that support force feedback). I'll go through a few more applications and see if anything not obvious is broken.
Thank you for taking a look.
Quoted 4 lines
Unfortunately, I only have that one wheel and I can only test USB connections at the moment (unless I find a proper serial adaptor, but I'm not sure if that would even work).
Quoted 7 lines
Quoted 2 lines
Are those patches planned to go into 4.19 or are they intended to be merged in the next development cycle?
Definitely not 4.19. Could be 4.20 or 4.21...
Thanks.
Quoted 8 lines
Hello Dmitry,
as a followup to the last E-Mail I sent about this topic, the complete chain of patches has been in my personal tree since September of 2018 and there have been no issues so far as well. I tested a few more games and utilities, and I was able to test with multiple wheels simultaneously as well.
In the end it's still your decision, but imo those patches should be fine
Thank you Tim, I'll put your name down as Tested-by then.
Signature · 1 line
Dmitry