Commit 06008152 authored by Pavel Rojtberg's avatar Pavel Rojtberg Committed by Dmitry Torokhov

Input: xpad - factor out URB submission in xpad_play_effect

Move submission logic to a single point at the end of the function.
This makes it easy to add locking/ queuing code later on.
Signed-off-by: default avatarPavel Rojtberg <rojtberg@gmail.com>
Signed-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent a306a65f
...@@ -762,80 +762,78 @@ static void xpad_deinit_output(struct usb_xpad *xpad) ...@@ -762,80 +762,78 @@ static void xpad_deinit_output(struct usb_xpad *xpad)
static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
{ {
struct usb_xpad *xpad = input_get_drvdata(dev); struct usb_xpad *xpad = input_get_drvdata(dev);
__u16 strong;
__u16 weak;
if (effect->type == FF_RUMBLE) { if (effect->type != FF_RUMBLE)
__u16 strong = effect->u.rumble.strong_magnitude; return 0;
__u16 weak = effect->u.rumble.weak_magnitude;
strong = effect->u.rumble.strong_magnitude;
switch (xpad->xtype) { weak = effect->u.rumble.weak_magnitude;
case XTYPE_XBOX: switch (xpad->xtype) {
xpad->odata[0] = 0x00; case XTYPE_XBOX:
xpad->odata[1] = 0x06; xpad->odata[0] = 0x00;
xpad->odata[2] = 0x00; xpad->odata[1] = 0x06;
xpad->odata[3] = strong / 256; /* left actuator */ xpad->odata[2] = 0x00;
xpad->odata[4] = 0x00; xpad->odata[3] = strong / 256; /* left actuator */
xpad->odata[5] = weak / 256; /* right actuator */ xpad->odata[4] = 0x00;
xpad->irq_out->transfer_buffer_length = 6; xpad->odata[5] = weak / 256; /* right actuator */
xpad->irq_out->transfer_buffer_length = 6;
return usb_submit_urb(xpad->irq_out, GFP_ATOMIC); break;
case XTYPE_XBOX360: case XTYPE_XBOX360:
xpad->odata[0] = 0x00; xpad->odata[0] = 0x00;
xpad->odata[1] = 0x08; xpad->odata[1] = 0x08;
xpad->odata[2] = 0x00; xpad->odata[2] = 0x00;
xpad->odata[3] = strong / 256; /* left actuator? */ xpad->odata[3] = strong / 256; /* left actuator? */
xpad->odata[4] = weak / 256; /* right actuator? */ xpad->odata[4] = weak / 256; /* right actuator? */
xpad->odata[5] = 0x00; xpad->odata[5] = 0x00;
xpad->odata[6] = 0x00; xpad->odata[6] = 0x00;
xpad->odata[7] = 0x00; xpad->odata[7] = 0x00;
xpad->irq_out->transfer_buffer_length = 8; xpad->irq_out->transfer_buffer_length = 8;
break;
return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
case XTYPE_XBOX360W:
case XTYPE_XBOX360W: xpad->odata[0] = 0x00;
xpad->odata[0] = 0x00; xpad->odata[1] = 0x01;
xpad->odata[1] = 0x01; xpad->odata[2] = 0x0F;
xpad->odata[2] = 0x0F; xpad->odata[3] = 0xC0;
xpad->odata[3] = 0xC0; xpad->odata[4] = 0x00;
xpad->odata[4] = 0x00; xpad->odata[5] = strong / 256;
xpad->odata[5] = strong / 256; xpad->odata[6] = weak / 256;
xpad->odata[6] = weak / 256; xpad->odata[7] = 0x00;
xpad->odata[7] = 0x00; xpad->odata[8] = 0x00;
xpad->odata[8] = 0x00; xpad->odata[9] = 0x00;
xpad->odata[9] = 0x00; xpad->odata[10] = 0x00;
xpad->odata[10] = 0x00; xpad->odata[11] = 0x00;
xpad->odata[11] = 0x00; xpad->irq_out->transfer_buffer_length = 12;
xpad->irq_out->transfer_buffer_length = 12; break;
return usb_submit_urb(xpad->irq_out, GFP_ATOMIC); case XTYPE_XBOXONE:
xpad->odata[0] = 0x09; /* activate rumble */
case XTYPE_XBOXONE: xpad->odata[1] = 0x08;
xpad->odata[0] = 0x09; /* activate rumble */ xpad->odata[2] = 0x00;
xpad->odata[1] = 0x08; xpad->odata[3] = 0x08; /* continuous effect */
xpad->odata[2] = 0x00; xpad->odata[4] = 0x00; /* simple rumble mode */
xpad->odata[3] = 0x08; /* continuous effect */ xpad->odata[5] = 0x03; /* L and R actuator only */
xpad->odata[4] = 0x00; /* simple rumble mode */ xpad->odata[6] = 0x00; /* TODO: LT actuator */
xpad->odata[5] = 0x03; /* L and R actuator only */ xpad->odata[7] = 0x00; /* TODO: RT actuator */
xpad->odata[6] = 0x00; /* TODO: LT actuator */ xpad->odata[8] = strong / 256; /* left actuator */
xpad->odata[7] = 0x00; /* TODO: RT actuator */ xpad->odata[9] = weak / 256; /* right actuator */
xpad->odata[8] = strong / 256; /* left actuator */ xpad->odata[10] = 0x80; /* length of pulse */
xpad->odata[9] = weak / 256; /* right actuator */ xpad->odata[11] = 0x00; /* stop period of pulse */
xpad->odata[10] = 0x80; /* length of pulse */ xpad->irq_out->transfer_buffer_length = 12;
xpad->odata[11] = 0x00; /* stop period of pulse */ break;
xpad->irq_out->transfer_buffer_length = 12;
default:
return usb_submit_urb(xpad->irq_out, GFP_ATOMIC); dev_dbg(&xpad->dev->dev,
"%s - rumble command sent to unsupported xpad type: %d\n",
default: __func__, xpad->xtype);
dev_dbg(&xpad->dev->dev, return -EINVAL;
"%s - rumble command sent to unsupported xpad type: %d\n",
__func__, xpad->xtype);
return -1;
}
} }
return 0; return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
} }
static int xpad_init_ff(struct usb_xpad *xpad) static int xpad_init_ff(struct usb_xpad *xpad)
......
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