lkml.org 
[lkml]   [2011]   [May]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] input: Add Nintendo extension controller driver
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.



\
 
 \ /
  Last update: 2011-05-16 23:53    [W:0.085 / U:0.040 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site