All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dtor@insightbb.com>
To: linux-input@atrey.karlin.mff.cuni.cz
Cc: linux-kernel@vger.kernel.org, Jan Kratochvil <honza@jikos.cz>,
	Jiri Kosina <jkosina@suse.cz>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-usb-devel@lists.sourceforge.net
Subject: Re: [PATCH 3/3] xpad.c: Added Xbox360 gamepad rumble support.
Date: Wed, 2 May 2007 22:55:43 -0400	[thread overview]
Message-ID: <200705022255.44746.dtor@insightbb.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0705021704180.13550@twin.jikos.cz>

On Wednesday 02 May 2007 11:05, Jan Kratochvil wrote:
>  	  
> +config XPAD_FF
> +	default n

Please don't default to anything.

>  
> +#ifdef CONFIG_XPAD_FF
> +/**
> + * xpad_irq_out
> + */

Comments are welcome when they say something...

> +static void xpad_irq_out(struct urb *urb)
> +{
> +	int retval;
> +
> +	switch (urb->status) {
> +		case 0:
> +		/* success */
> +		break;
> +		case -ECONNRESET:
> +		case -ENOENT:
> +		case -ESHUTDOWN:
> +			/* this urb is terminated, clean up */
> +			dbg("%s - urb shutting down with status: %d",  __FUNCTION__, urb->status);
> +			return;
> +		default:
> +			dbg("%s - nonzero urb status received: %d",  __FUNCTION__, urb->status);
> +			goto exit;
> +	}
> +
> +exit:
> +	retval = usb_submit_urb(urb, GFP_ATOMIC);
> +	if (retval)
> +		err("%s - usb_submit_urb failed with result %d",
> +		   __FUNCTION__, retval);
> +} 
> +
> +int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
> +{
> +	struct usb_xpad *xpad = dev->private;
> +	if (effect->type == FF_RUMBLE) {
> +		__u16 strong = effect->u.rumble.strong_magnitude;
> +		__u16 weak = effect->u.rumble.weak_magnitude;
> +		xpad->odata[0] = 0x00; 
> +		xpad->odata[1] = 0x08; 
> +		xpad->odata[2] = 0x00; 
> +		xpad->odata[3] = strong / 256;
> +		xpad->odata[4] = weak / 256; 
> +		xpad->odata[5] = 0x00;
> +		xpad->odata[6] = 0x00;
> +		xpad->odata[7] = 0x00;
> +		usb_submit_urb(xpad->irq_out, GFP_KERNEL);
> +	}
> +
> +	return 0;
> +}
> +
> +static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad)
> +{
> +	if (xpad->flags & XPAD_FLAGS_XBOX360) {
> +		struct usb_endpoint_descriptor *ep_irq_out;
> +		int rv;
> +
> +		xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 
> +					       GFP_ATOMIC, &xpad->odata_dma );
> +		if (!xpad->idata)
> +			goto fail1;
> +
> +		xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
> +		if (!xpad->irq_out)
> +			goto fail2;
> +
> +
> +		ep_irq_out = &intf->cur_altsetting->endpoint[1].desc;
> +		usb_fill_int_urb(xpad->irq_out, xpad->udev,
> +				 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
> +				 xpad->odata, XPAD_PKT_LEN,
> +				 xpad_irq_out, xpad, ep_irq_out->bInterval);
> +		xpad->irq_out->transfer_dma = xpad->odata_dma;
> +		xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
> +
> +		set_bit( FF_RUMBLE, xpad->dev->ffbit );
> +		rv = input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
> +

Error handling seems to be missing.

> +		return 0;
> +
> +fail2:		usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
> +fail1:		
> +		return -ENOMEM;
> +	}
> +	return 0;
> +}
> +
> +static void xpad_deinit_ff(struct usb_interface *intf, struct usb_xpad *xpad)
> +{
> +	if (xpad->flags & XPAD_FLAGS_XBOX360) {
> +		usb_kill_urb(xpad->irq_out);

You may want to do that in xpad_close().

> +		usb_free_urb(xpad->irq_out);
> +		usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN,
> +				xpad->odata, xpad->odata_dma);
> +	}
> +}
> +#endif
> +
>  static int xpad_open (struct input_dev *dev)
>  {
>  	struct usb_xpad *xpad = dev->private;
> @@ -432,6 +535,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
>  
>  	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
>  
> +#ifdef CONFIG_XPAD_FF
> +	if (xpad->flags & XPAD_FLAGS_XBOX360)
> +		input_dev->evbit[0] |= BIT(EV_FF);
> +#endif

Can this be moved into xpad_init_ff?

> +
>  	/* set up buttons */
>  	for (i = 0; xpad_btn[i] >= 0; i++)
>  		set_bit(xpad_btn[i], input_dev->keybit);
> @@ -449,6 +557,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
>  		for (i = 0; xpad_abs_pad[i] >= 0; i++)
>  		    xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
>  
> +#ifdef CONFIG_XPAD_FF
> +	if (xpad_init_ff(intf, xpad))
> +		goto fail2;
> +#endif
> +

Normally we define dummy fucntions when corresponding config option is disabled
to avoid littering main code with #ifdefs.

>  	ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
>  	usb_fill_int_urb(xpad->irq_in, udev,
>  			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
> @@ -476,6 +589,9 @@ static void xpad_disconnect(struct usb_interface *intf)
>  	usb_set_intfdata(intf, NULL);
>  	if (xpad) {
>  		usb_kill_urb(xpad->irq_in);

This is extra - we already did that in xpad_close.

> +#ifdef CONFIG_XPAD_FF
> +		xpad_deinit_ff(intf, xpad);
> +#endif
>  		input_unregister_device(xpad->dev);
>  		usb_free_urb(xpad->irq_in);
>  		usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN,

-- 
Dmitry

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
linux-usb-devel@lists.sourceforge.net
To unsubscribe, use the last form field at:
https://lists.sourceforge.net/lists/listinfo/linux-usb-devel

WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Torokhov <dtor@insightbb.com>
To: linux-input@atrey.karlin.mff.cuni.cz
Cc: Jan Kratochvil <honza@jikos.cz>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	linux-usb-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Jiri Kosina <jkosina@suse.cz>
Subject: Re: [PATCH 3/3] xpad.c: Added Xbox360 gamepad rumble support.
Date: Wed, 2 May 2007 22:55:43 -0400	[thread overview]
Message-ID: <200705022255.44746.dtor@insightbb.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0705021704180.13550@twin.jikos.cz>

On Wednesday 02 May 2007 11:05, Jan Kratochvil wrote:
>  	  
> +config XPAD_FF
> +	default n

Please don't default to anything.

>  
> +#ifdef CONFIG_XPAD_FF
> +/**
> + * xpad_irq_out
> + */

Comments are welcome when they say something...

> +static void xpad_irq_out(struct urb *urb)
> +{
> +	int retval;
> +
> +	switch (urb->status) {
> +		case 0:
> +		/* success */
> +		break;
> +		case -ECONNRESET:
> +		case -ENOENT:
> +		case -ESHUTDOWN:
> +			/* this urb is terminated, clean up */
> +			dbg("%s - urb shutting down with status: %d",  __FUNCTION__, urb->status);
> +			return;
> +		default:
> +			dbg("%s - nonzero urb status received: %d",  __FUNCTION__, urb->status);
> +			goto exit;
> +	}
> +
> +exit:
> +	retval = usb_submit_urb(urb, GFP_ATOMIC);
> +	if (retval)
> +		err("%s - usb_submit_urb failed with result %d",
> +		   __FUNCTION__, retval);
> +} 
> +
> +int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
> +{
> +	struct usb_xpad *xpad = dev->private;
> +	if (effect->type == FF_RUMBLE) {
> +		__u16 strong = effect->u.rumble.strong_magnitude;
> +		__u16 weak = effect->u.rumble.weak_magnitude;
> +		xpad->odata[0] = 0x00; 
> +		xpad->odata[1] = 0x08; 
> +		xpad->odata[2] = 0x00; 
> +		xpad->odata[3] = strong / 256;
> +		xpad->odata[4] = weak / 256; 
> +		xpad->odata[5] = 0x00;
> +		xpad->odata[6] = 0x00;
> +		xpad->odata[7] = 0x00;
> +		usb_submit_urb(xpad->irq_out, GFP_KERNEL);
> +	}
> +
> +	return 0;
> +}
> +
> +static int xpad_init_ff(struct usb_interface *intf, struct usb_xpad *xpad)
> +{
> +	if (xpad->flags & XPAD_FLAGS_XBOX360) {
> +		struct usb_endpoint_descriptor *ep_irq_out;
> +		int rv;
> +
> +		xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 
> +					       GFP_ATOMIC, &xpad->odata_dma );
> +		if (!xpad->idata)
> +			goto fail1;
> +
> +		xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL);
> +		if (!xpad->irq_out)
> +			goto fail2;
> +
> +
> +		ep_irq_out = &intf->cur_altsetting->endpoint[1].desc;
> +		usb_fill_int_urb(xpad->irq_out, xpad->udev,
> +				 usb_sndintpipe(xpad->udev, ep_irq_out->bEndpointAddress),
> +				 xpad->odata, XPAD_PKT_LEN,
> +				 xpad_irq_out, xpad, ep_irq_out->bInterval);
> +		xpad->irq_out->transfer_dma = xpad->odata_dma;
> +		xpad->irq_out->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
> +
> +		set_bit( FF_RUMBLE, xpad->dev->ffbit );
> +		rv = input_ff_create_memless(xpad->dev, NULL, xpad_play_effect);
> +

Error handling seems to be missing.

> +		return 0;
> +
> +fail2:		usb_buffer_free(xpad->udev, XPAD_PKT_LEN, xpad->odata, xpad->odata_dma);
> +fail1:		
> +		return -ENOMEM;
> +	}
> +	return 0;
> +}
> +
> +static void xpad_deinit_ff(struct usb_interface *intf, struct usb_xpad *xpad)
> +{
> +	if (xpad->flags & XPAD_FLAGS_XBOX360) {
> +		usb_kill_urb(xpad->irq_out);

You may want to do that in xpad_close().

> +		usb_free_urb(xpad->irq_out);
> +		usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN,
> +				xpad->odata, xpad->odata_dma);
> +	}
> +}
> +#endif
> +
>  static int xpad_open (struct input_dev *dev)
>  {
>  	struct usb_xpad *xpad = dev->private;
> @@ -432,6 +535,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
>  
>  	input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
>  
> +#ifdef CONFIG_XPAD_FF
> +	if (xpad->flags & XPAD_FLAGS_XBOX360)
> +		input_dev->evbit[0] |= BIT(EV_FF);
> +#endif

Can this be moved into xpad_init_ff?

> +
>  	/* set up buttons */
>  	for (i = 0; xpad_btn[i] >= 0; i++)
>  		set_bit(xpad_btn[i], input_dev->keybit);
> @@ -449,6 +557,11 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
>  		for (i = 0; xpad_abs_pad[i] >= 0; i++)
>  		    xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
>  
> +#ifdef CONFIG_XPAD_FF
> +	if (xpad_init_ff(intf, xpad))
> +		goto fail2;
> +#endif
> +

Normally we define dummy fucntions when corresponding config option is disabled
to avoid littering main code with #ifdefs.

>  	ep_irq_in = &intf->cur_altsetting->endpoint[0].desc;
>  	usb_fill_int_urb(xpad->irq_in, udev,
>  			 usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
> @@ -476,6 +589,9 @@ static void xpad_disconnect(struct usb_interface *intf)
>  	usb_set_intfdata(intf, NULL);
>  	if (xpad) {
>  		usb_kill_urb(xpad->irq_in);

This is extra - we already did that in xpad_close.

> +#ifdef CONFIG_XPAD_FF
> +		xpad_deinit_ff(intf, xpad);
> +#endif
>  		input_unregister_device(xpad->dev);
>  		usb_free_urb(xpad->irq_in);
>  		usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN,

-- 
Dmitry

  reply	other threads:[~2007-05-03  2:55 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-02 15:05 [PATCH 3/3] xpad.c: Added Xbox360 gamepad rumble support Jan Kratochvil
2007-05-02 15:05 ` Jan Kratochvil
2007-05-03  2:55 ` Dmitry Torokhov [this message]
2007-05-03  2:55   ` Dmitry Torokhov
2007-05-03 13:04 ` Jan Kratochvil
2007-05-03 21:41   ` Jan Kratochvil
2007-05-09  4:31     ` Dmitry Torokhov
2007-05-09  4:29   ` Dmitry Torokhov
2007-05-09  4:29     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200705022255.44746.dtor@insightbb.com \
    --to=dtor@insightbb.com \
    --cc=gregkh@suse.de \
    --cc=honza@jikos.cz \
    --cc=jkosina@suse.cz \
    --cc=linux-input@atrey.karlin.mff.cuni.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.