linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Dooks <ben@trinity.fluff.org>
To: Grant Likely <grant.likely@secretlab.ca>
Cc: simon@mungewell.org, Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	OliverNeukumoliver@neukum.org
Subject: Re: [PATCH] input: Add Nintendo extension controller driver
Date: Mon, 16 May 2011 22:51:10 +0100	[thread overview]
Message-ID: <20110516215110.GE16731@trinity.fluff.org> (raw)
In-Reply-To: <20110516214608.17011.3075.stgit@ponder>

On Mon, May 16, 2011 at 03:46:08PM -0600, Grant Likely wrote:
> This driver adds support for Nintendo Wiimote extension controllers
> directly attached to an i2c bus, such as when using an adaptor like
> the Wiichuck.
> 
> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
> ---
>  drivers/input/joystick/Kconfig    |   13 +
>  drivers/input/joystick/Makefile   |    1 
>  drivers/input/joystick/wiichuck.c |  441 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 455 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/joystick/wiichuck.c
> 
> diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
> index 56eb471..5b7fba7 100644
> --- a/drivers/input/joystick/Kconfig
> +++ b/drivers/input/joystick/Kconfig
> @@ -193,6 +193,19 @@ config JOYSTICK_TWIDJOY
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called twidjoy.
>  
> +config JOYSTICK_WIICHUCK
> +	tristate "Nintendo Wiimote Extension connector on i2c bus"
> +	depends on I2C
> +	select INPUT_POLLDEV
> +	help
> +	  Say Y here if you have a Nintendo Wiimote extension connector
> +	  attached directly to an i2c bus, like the Sparcfun Wiichuck adapter
> +	  board.  This driver supports both the Nunchuck and the Classic
> +	  Controller extensions.
> +
> +	  To compile this driver as a module, choose M here: the
> +	  modules will be called wiichuck.
> +
>  config JOYSTICK_ZHENHUA
>  	tristate "5-byte Zhenhua RC transmitter"
>  	select SERIO
> diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile
> index 92dc0de..78466d6 100644
> --- a/drivers/input/joystick/Makefile
> +++ b/drivers/input/joystick/Makefile
> @@ -29,6 +29,7 @@ obj-$(CONFIG_JOYSTICK_TMDC)		+= tmdc.o
>  obj-$(CONFIG_JOYSTICK_TURBOGRAFX)	+= turbografx.o
>  obj-$(CONFIG_JOYSTICK_TWIDJOY)		+= twidjoy.o
>  obj-$(CONFIG_JOYSTICK_WARRIOR)		+= warrior.o
> +obj-$(CONFIG_JOYSTICK_WIICHUCK)		+= wiichuck.o
>  obj-$(CONFIG_JOYSTICK_XPAD)		+= xpad.o
>  obj-$(CONFIG_JOYSTICK_ZHENHUA)		+= zhenhua.o
>  obj-$(CONFIG_JOYSTICK_WALKERA0701)	+= walkera0701.o
> diff --git a/drivers/input/joystick/wiichuck.c b/drivers/input/joystick/wiichuck.c
> new file mode 100644
> index 0000000..85a194f
> --- /dev/null
> +++ b/drivers/input/joystick/wiichuck.c
> @@ -0,0 +1,441 @@
> +/*
> + * i2c Wiichuck driver (Nintendo Wiimote accessory connector)
> + *
> + * This driver supports Nintendo Wiimote accessories like the Nunchuck and
> + * the Classic Controller connected to an i2c bus.
> + *
> + * Copyright (c) 2011 Secret Lab Technologies Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of version 2 of the GNU General Public License as
> + * published by the Free Software Foundation.
> + *
> + * This driver uses the polled input device abstraction to implement an
> + * input driver for Nintendo expansion devices wired up to an i2c bus.
> + *
> + * A state machine implements the protocol handling.  It starts in the
> + * DISCONNECTED state initially and polls every second waiting for a
> + * device to get attached, and reading the device id when one does.
> + * If the device is recognized, then the polling period is bumped up
> + * to 50ms, and the state machine enters into a loop alternating
> + * between writing the data address (which triggers data capture) and
> + * reading the data block out of the device.  If at any time the
> + * device is disconnected, then it goes back to DISCONNECTED state and
> + * drops the polling frequency back down to 1 second.
> + *
> + * A callback is implemented for each supported devices, currently the
> + * Nunchuck and the Classic Controller.  Wii Motion Plus has yet to be
> + * added.
> + */
> +
> +#include <linux/cache.h>
> +#include <linux/delay.h>
> +#include <linux/i2c.h>
> +#include <linux/interrupt.h>
> +#include <linux/input.h>
> +#include <linux/input-polldev.h>
> +#include <linux/mod_devicetable.h>
> +#include <linux/slab.h>
> +
> +MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
> +MODULE_DESCRIPTION("Wiichuck (i2c Nintendo Wiimote accessory) driver");
> +MODULE_LICENSE("GPL");
> +
> +#define WIICHUCK_POLL_PERIOD	(1000)	/* 1 second */
> +#ifdef DEBUG
> +#define WIICHUCK_CAPTURE_PERIOD (500)	/* 1/2 second for debug */
> +#else
> +#define WIICHUCK_CAPTURE_PERIOD (100)	/* 100 milliseconds */
> +#endif /* DEBUG */
> +
> +enum wiichuck_state {
> +	WIICHUCK_STATE_DISCONNECTED = 0,
> +	WIICHUCK_STATE_DATA,
> +};
> +
> +struct wiichuck_device {
> +	struct input_polled_dev *poll_dev;
> +	struct i2c_client *i2c_client;
> +	int (*process)(struct wiichuck_device *wiichuck);
> +	enum wiichuck_state state;
> +
> +	/*
> +	 * DMA buffer, with padding to give it its own cache line so that
> +	 * the DMA streaming works on non-coherent architectures.
> +	 * Question: Is this the proper pattern, and is this really necessary?
> +	 */
> +	uint8_t pad1[L1_CACHE_BYTES];
> +	uint8_t buf[6];
> +	uint8_t pad2[L1_CACHE_BYTES];
> +};

I think there's an attribute to do this, starting with an __ defined
in the kernel.

-- 
Ben Dooks, ben@fluff.org, http://www.fluff.org/ben/

Large Hadron Colada: A large Pina Colada that makes the universe disappear.


  reply	other threads:[~2011-05-16 21:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-16 21:46 [PATCH] input: Add Nintendo extension controller driver Grant Likely
2011-05-16 21:51 ` Ben Dooks [this message]
2011-05-16 22:43   ` Dmitry Torokhov
2011-05-16 23:04     ` Grant Likely
2011-05-16 21:56 ` Grant Likely
2011-05-23 20:50 ` Peter Korsgaard
2011-05-27  8:01   ` Grant Likely
  -- strict thread matches above, loose matches on Subject: below --
2011-05-27  8:14 Grant Likely
2011-08-01 16:04 ` Grant Likely
2011-08-01 16:38   ` Dmitry Torokhov
2011-08-01 16:44     ` Grant Likely

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=20110516215110.GE16731@trinity.fluff.org \
    --to=ben@trinity.fluff.org \
    --cc=OliverNeukumoliver@neukum.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=grant.likely@secretlab.ca \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=simon@mungewell.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).