2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* NES, SNES, N64, MultiSystem, PSX gamepad driver for Linux
|
|
|
|
*
|
2005-05-29 01:28:55 -06:00
|
|
|
* Copyright (c) 1999-2004 Vojtech Pavlik <vojtech@suse.cz>
|
|
|
|
* Copyright (c) 2004 Peter Nelson <rufus-kernel@hackish.org>
|
2005-04-16 16:20:36 -06:00
|
|
|
*
|
|
|
|
* Based on the work of:
|
2005-05-29 01:28:55 -06:00
|
|
|
* Andree Borrmann John Dahlstrom
|
|
|
|
* David Kuder Nathan Hand
|
2006-04-01 22:10:05 -07:00
|
|
|
* Raphael Assenat
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Should you need to contact me, the author, you can do so either by
|
|
|
|
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
|
|
|
|
* Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:55:31 -07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/parport.h>
|
|
|
|
#include <linux/input.h>
|
2006-02-18 22:22:30 -07:00
|
|
|
#include <linux/mutex.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
|
|
|
|
MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
#define GC_MAX_PORTS 3
|
|
|
|
#define GC_MAX_DEVICES 5
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
struct gc_config {
|
|
|
|
int args[GC_MAX_DEVICES + 1];
|
2007-05-02 22:52:51 -06:00
|
|
|
unsigned int nargs;
|
2005-09-15 01:01:52 -06:00
|
|
|
};
|
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static struct gc_config gc_cfg[GC_MAX_PORTS];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-05-02 22:52:51 -06:00
|
|
|
module_param_array_named(map, gc_cfg[0].args, int, &gc_cfg[0].nargs, 0);
|
2005-09-15 01:01:52 -06:00
|
|
|
MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<pad1>,<pad2>,..<pad5>)");
|
2007-05-02 22:52:51 -06:00
|
|
|
module_param_array_named(map2, gc_cfg[1].args, int, &gc_cfg[1].nargs, 0);
|
2005-09-15 01:01:52 -06:00
|
|
|
MODULE_PARM_DESC(map2, "Describes second set of devices");
|
2007-05-02 22:52:51 -06:00
|
|
|
module_param_array_named(map3, gc_cfg[2].args, int, &gc_cfg[2].nargs, 0);
|
2005-09-15 01:01:52 -06:00
|
|
|
MODULE_PARM_DESC(map3, "Describes third set of devices");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/* see also gs_psx_delay parameter in PSX support section */
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
enum gc_type {
|
|
|
|
GC_NONE = 0,
|
|
|
|
GC_SNES,
|
|
|
|
GC_NES,
|
|
|
|
GC_NES4,
|
|
|
|
GC_MULTI,
|
|
|
|
GC_MULTI2,
|
|
|
|
GC_N64,
|
|
|
|
GC_PSX,
|
|
|
|
GC_DDR,
|
|
|
|
GC_SNESMOUSE,
|
|
|
|
GC_MAX
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define GC_REFRESH_TIME HZ/100
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
struct gc_pad {
|
|
|
|
struct input_dev *dev;
|
|
|
|
enum gc_type type;
|
|
|
|
char phys[32];
|
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
struct gc {
|
|
|
|
struct pardevice *pd;
|
2010-02-21 21:54:54 -07:00
|
|
|
struct gc_pad pads[GC_MAX_DEVICES];
|
2005-04-16 16:20:36 -06:00
|
|
|
struct timer_list timer;
|
2010-02-21 21:54:54 -07:00
|
|
|
int pad_count[GC_MAX];
|
2005-04-16 16:20:36 -06:00
|
|
|
int used;
|
2015-09-29 17:03:43 -06:00
|
|
|
int parportno;
|
2006-02-18 22:22:30 -07:00
|
|
|
struct mutex mutex;
|
2005-04-16 16:20:36 -06:00
|
|
|
};
|
|
|
|
|
2010-02-21 21:53:55 -07:00
|
|
|
struct gc_subdev {
|
|
|
|
unsigned int idx;
|
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
static struct gc *gc_base[3];
|
|
|
|
|
2010-02-21 21:55:09 -07:00
|
|
|
static const int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:55:09 -07:00
|
|
|
static const char *gc_names[] = {
|
2010-02-21 21:54:28 -07:00
|
|
|
NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
|
|
|
|
"Multisystem 2-button joystick", "N64 controller", "PSX controller",
|
|
|
|
"PSX DDR controller", "SNES mouse"
|
|
|
|
};
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* N64 support.
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:55:09 -07:00
|
|
|
static const unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
|
|
|
|
static const short gc_n64_btn[] = {
|
2010-02-21 21:54:28 -07:00
|
|
|
BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
|
|
|
|
BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */
|
2010-02-21 21:53:55 -07:00
|
|
|
#define GC_N64_STOP_LENGTH 5 /* Length of encoded stop bit */
|
|
|
|
#define GC_N64_CMD_00 0x11111111UL
|
|
|
|
#define GC_N64_CMD_01 0xd1111111UL
|
|
|
|
#define GC_N64_CMD_03 0xdd111111UL
|
|
|
|
#define GC_N64_CMD_1b 0xdd1dd111UL
|
|
|
|
#define GC_N64_CMD_c0 0x111111ddUL
|
|
|
|
#define GC_N64_CMD_80 0x1111111dUL
|
|
|
|
#define GC_N64_STOP_BIT 0x1d /* Encoded stop bit */
|
|
|
|
#define GC_N64_REQUEST_DATA GC_N64_CMD_01 /* the request data command */
|
2005-04-16 16:20:36 -06:00
|
|
|
#define GC_N64_DELAY 133 /* delay between transmit request, and response ready (us) */
|
|
|
|
#define GC_N64_DWS 3 /* delay between write segments (required for sound playback because of ISA DMA) */
|
|
|
|
/* GC_N64_DWS > 24 is known to fail */
|
|
|
|
#define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */
|
|
|
|
#define GC_N64_POWER_R 0xfd /* power during read */
|
|
|
|
#define GC_N64_OUT 0x1d /* output bits to the 4 pads */
|
|
|
|
/* Reading the main axes of any N64 pad is known to fail if the corresponding bit */
|
|
|
|
/* in GC_N64_OUT is pulled low on the output port (by any routine) for more */
|
|
|
|
/* than 123 us */
|
|
|
|
#define GC_N64_CLOCK 0x02 /* clock bits for read */
|
|
|
|
|
2010-02-21 21:53:55 -07:00
|
|
|
/*
|
|
|
|
* Used for rumble code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Send encoded command */
|
|
|
|
static void gc_n64_send_command(struct gc *gc, unsigned long cmd,
|
|
|
|
unsigned char target)
|
|
|
|
{
|
|
|
|
struct parport *port = gc->pd->port;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < GC_N64_LENGTH; i++) {
|
|
|
|
unsigned char data = (cmd >> i) & 1 ? target : 0;
|
|
|
|
parport_write_data(port, GC_N64_POWER_W | data);
|
|
|
|
udelay(GC_N64_DWS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send stop bit */
|
|
|
|
static void gc_n64_send_stop_bit(struct gc *gc, unsigned char target)
|
|
|
|
{
|
|
|
|
struct parport *port = gc->pd->port;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < GC_N64_STOP_LENGTH; i++) {
|
|
|
|
unsigned char data = (GC_N64_STOP_BIT >> i) & 1 ? target : 0;
|
|
|
|
parport_write_data(port, GC_N64_POWER_W | data);
|
|
|
|
udelay(GC_N64_DWS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* gc_n64_read_packet() reads an N64 packet.
|
2010-02-21 21:54:28 -07:00
|
|
|
* Each pad uses one bit per byte. So all pads connected to this port
|
|
|
|
* are read in parallel.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request the pad to transmit data
|
|
|
|
*/
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
2010-02-21 21:53:55 -07:00
|
|
|
gc_n64_send_command(gc, GC_N64_REQUEST_DATA, GC_N64_OUT);
|
|
|
|
gc_n64_send_stop_bit(gc, GC_N64_OUT);
|
2005-04-16 16:20:36 -06:00
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
/*
|
2010-02-21 21:54:28 -07:00
|
|
|
* Wait for the pad response to be loaded into the 33-bit register
|
|
|
|
* of the adapter.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
udelay(GC_N64_DELAY);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Grab data (ignoring the last bit, which is a stop bit)
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < GC_N64_LENGTH; i++) {
|
|
|
|
parport_write_data(gc->pd->port, GC_N64_POWER_R);
|
2010-02-21 21:53:55 -07:00
|
|
|
udelay(2);
|
2005-04-16 16:20:36 -06:00
|
|
|
data[i] = parport_read_status(gc->pd->port);
|
|
|
|
parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2010-02-21 21:54:28 -07:00
|
|
|
* We must wait 200 ms here for the controller to reinitialize before
|
|
|
|
* the next read request. No worries as long as gc_read is polled less
|
|
|
|
* frequently than this.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
static void gc_n64_process_packet(struct gc *gc)
|
|
|
|
{
|
|
|
|
unsigned char data[GC_N64_LENGTH];
|
|
|
|
struct input_dev *dev;
|
|
|
|
int i, j, s;
|
2010-02-21 21:54:28 -07:00
|
|
|
signed char x, y;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
gc_n64_read_packet(gc, data);
|
|
|
|
|
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++) {
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pads[i].type != GC_N64)
|
2006-01-29 19:52:04 -07:00
|
|
|
continue;
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
dev = gc->pads[i].dev;
|
2006-01-29 19:52:04 -07:00
|
|
|
s = gc_status_bit[i];
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (s & ~(data[8] | data[9])) {
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
x = y = 0;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
for (j = 0; j < 8; j++) {
|
|
|
|
if (data[23 - j] & s)
|
2010-02-21 21:54:28 -07:00
|
|
|
x |= 1 << j;
|
2006-01-29 19:52:04 -07:00
|
|
|
if (data[31 - j] & s)
|
2010-02-21 21:54:28 -07:00
|
|
|
y |= 1 << j;
|
2006-01-29 19:52:04 -07:00
|
|
|
}
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_abs(dev, ABS_X, x);
|
|
|
|
input_report_abs(dev, ABS_Y, -y);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_abs(dev, ABS_HAT0X,
|
|
|
|
!(s & data[6]) - !(s & data[7]));
|
|
|
|
input_report_abs(dev, ABS_HAT0Y,
|
|
|
|
!(s & data[4]) - !(s & data[5]));
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
for (j = 0; j < 10; j++)
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, gc_n64_btn[j],
|
|
|
|
s & data[gc_n64_bytes[j]]);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
input_sync(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-21 21:53:55 -07:00
|
|
|
static int gc_n64_play_effect(struct input_dev *dev, void *data,
|
|
|
|
struct ff_effect *effect)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
struct gc *gc = input_get_drvdata(dev);
|
|
|
|
struct gc_subdev *sdev = data;
|
|
|
|
unsigned char target = 1 << sdev->idx; /* select desired pin */
|
|
|
|
|
|
|
|
if (effect->type == FF_RUMBLE) {
|
|
|
|
struct ff_rumble_effect *rumble = &effect->u.rumble;
|
|
|
|
unsigned int cmd =
|
|
|
|
rumble->strong_magnitude || rumble->weak_magnitude ?
|
|
|
|
GC_N64_CMD_01 : GC_N64_CMD_00;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
|
|
|
/* Init Rumble - 0x03, 0x80, 0x01, (34)0x80 */
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_03, target);
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_80, target);
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_01, target);
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_80, target);
|
|
|
|
gc_n64_send_stop_bit(gc, target);
|
|
|
|
|
|
|
|
udelay(GC_N64_DELAY);
|
|
|
|
|
|
|
|
/* Now start or stop it - 0x03, 0xc0, 0zx1b, (32)0x01/0x00 */
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_03, target);
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_c0, target);
|
|
|
|
gc_n64_send_command(gc, GC_N64_CMD_1b, target);
|
|
|
|
for (i = 0; i < 32; i++)
|
|
|
|
gc_n64_send_command(gc, cmd, target);
|
|
|
|
gc_n64_send_stop_bit(gc, target);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static int gc_n64_init_ff(struct input_dev *dev, int i)
|
2010-02-21 21:53:55 -07:00
|
|
|
{
|
|
|
|
struct gc_subdev *sdev;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
sdev = kmalloc(sizeof(*sdev), GFP_KERNEL);
|
|
|
|
if (!sdev)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
sdev->idx = i;
|
|
|
|
|
|
|
|
input_set_capability(dev, EV_FF, FF_RUMBLE);
|
|
|
|
|
|
|
|
err = input_ff_create_memless(dev, sdev, gc_n64_play_effect);
|
|
|
|
if (err) {
|
|
|
|
kfree(sdev);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* NES/SNES support.
|
|
|
|
*/
|
|
|
|
|
2006-04-01 22:10:05 -07:00
|
|
|
#define GC_NES_DELAY 6 /* Delay between bits - 6us */
|
|
|
|
#define GC_NES_LENGTH 8 /* The NES pads use 8 bits of data */
|
|
|
|
#define GC_SNES_LENGTH 12 /* The SNES true length is 16, but the
|
|
|
|
last 4 bits are unused */
|
|
|
|
#define GC_SNESMOUSE_LENGTH 32 /* The SNES mouse uses 32 bits, the first
|
|
|
|
16 bits are equivalent to a gamepad */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
#define GC_NES_POWER 0xfc
|
|
|
|
#define GC_NES_CLOCK 0x01
|
|
|
|
#define GC_NES_LATCH 0x02
|
|
|
|
|
2010-02-21 21:55:09 -07:00
|
|
|
static const unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 };
|
|
|
|
static const unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
|
|
|
|
static const short gc_snes_btn[] = {
|
2010-02-21 21:54:28 -07:00
|
|
|
BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* gc_nes_read_packet() reads a NES/SNES packet.
|
|
|
|
* Each pad uses one bit per byte. So all pads connected to
|
|
|
|
* this port are read in parallel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK | GC_NES_LATCH);
|
|
|
|
udelay(GC_NES_DELAY * 2);
|
|
|
|
parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
udelay(GC_NES_DELAY);
|
|
|
|
parport_write_data(gc->pd->port, GC_NES_POWER);
|
|
|
|
data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
|
|
|
|
udelay(GC_NES_DELAY);
|
|
|
|
parport_write_data(gc->pd->port, GC_NES_POWER | GC_NES_CLOCK);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
static void gc_nes_process_packet(struct gc *gc)
|
|
|
|
{
|
2006-04-01 22:10:05 -07:00
|
|
|
unsigned char data[GC_SNESMOUSE_LENGTH];
|
2010-02-21 21:54:54 -07:00
|
|
|
struct gc_pad *pad;
|
2006-01-29 19:52:04 -07:00
|
|
|
struct input_dev *dev;
|
2006-04-01 22:10:05 -07:00
|
|
|
int i, j, s, len;
|
|
|
|
char x_rel, y_rel;
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
len = gc->pad_count[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH :
|
|
|
|
(gc->pad_count[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2006-04-01 22:10:05 -07:00
|
|
|
gc_nes_read_packet(gc, len, data);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++) {
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
pad = &gc->pads[i];
|
2010-07-20 21:25:35 -06:00
|
|
|
dev = pad->dev;
|
2006-01-29 19:52:04 -07:00
|
|
|
s = gc_status_bit[i];
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
switch (pad->type) {
|
|
|
|
|
|
|
|
case GC_NES:
|
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
|
|
|
|
input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
|
|
|
|
|
|
|
|
for (j = 0; j < 4; j++)
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, gc_snes_btn[j],
|
|
|
|
s & data[gc_nes_bytes[j]]);
|
2010-02-21 21:54:54 -07:00
|
|
|
input_sync(dev);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_SNES:
|
|
|
|
|
|
|
|
input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
|
|
|
|
input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
for (j = 0; j < 8; j++)
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, gc_snes_btn[j],
|
|
|
|
s & data[gc_snes_bytes[j]]);
|
2010-02-21 21:54:54 -07:00
|
|
|
input_sync(dev);
|
|
|
|
break;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
case GC_SNESMOUSE:
|
2006-04-01 22:10:05 -07:00
|
|
|
/*
|
2010-02-21 21:54:28 -07:00
|
|
|
* The 4 unused bits from SNES controllers appear
|
|
|
|
* to be ID bits so use them to make sure we are
|
|
|
|
* dealing with a mouse.
|
2006-04-01 22:10:05 -07:00
|
|
|
* gamepad is connected. This is important since
|
|
|
|
* my SNES gamepad sends 1's for bits 16-31, which
|
|
|
|
* cause the mouse pointer to quickly move to the
|
|
|
|
* upper left corner of the screen.
|
|
|
|
*/
|
|
|
|
if (!(s & data[12]) && !(s & data[13]) &&
|
|
|
|
!(s & data[14]) && (s & data[15])) {
|
|
|
|
input_report_key(dev, BTN_LEFT, s & data[9]);
|
|
|
|
input_report_key(dev, BTN_RIGHT, s & data[8]);
|
|
|
|
|
|
|
|
x_rel = y_rel = 0;
|
|
|
|
for (j = 0; j < 7; j++) {
|
|
|
|
x_rel <<= 1;
|
|
|
|
if (data[25 + j] & s)
|
|
|
|
x_rel |= 1;
|
|
|
|
|
|
|
|
y_rel <<= 1;
|
|
|
|
if (data[17 + j] & s)
|
|
|
|
y_rel |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x_rel) {
|
|
|
|
if (data[24] & s)
|
|
|
|
x_rel = -x_rel;
|
|
|
|
input_report_rel(dev, REL_X, x_rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y_rel) {
|
|
|
|
if (data[16] & s)
|
|
|
|
y_rel = -y_rel;
|
|
|
|
input_report_rel(dev, REL_Y, y_rel);
|
|
|
|
}
|
2010-02-21 21:54:54 -07:00
|
|
|
|
|
|
|
input_sync(dev);
|
2006-04-01 22:10:05 -07:00
|
|
|
}
|
2010-02-21 21:54:54 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2006-04-01 22:10:05 -07:00
|
|
|
}
|
2006-01-29 19:52:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* Multisystem joystick support
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define GC_MULTI_LENGTH 5 /* Multi system joystick packet length is 5 */
|
|
|
|
#define GC_MULTI2_LENGTH 6 /* One more bit for one more button */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gc_multi_read_packet() reads a Multisystem joystick packet.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
parport_write_data(gc->pd->port, ~(1 << i));
|
|
|
|
data[i] = parport_read_status(gc->pd->port) ^ 0x7f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
static void gc_multi_process_packet(struct gc *gc)
|
|
|
|
{
|
|
|
|
unsigned char data[GC_MULTI2_LENGTH];
|
2010-02-21 21:54:54 -07:00
|
|
|
int data_len = gc->pad_count[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH;
|
|
|
|
struct gc_pad *pad;
|
2006-01-29 19:52:04 -07:00
|
|
|
struct input_dev *dev;
|
|
|
|
int i, s;
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
gc_multi_read_packet(gc, data_len, data);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++) {
|
2010-02-21 21:54:54 -07:00
|
|
|
pad = &gc->pads[i];
|
|
|
|
dev = pad->dev;
|
2006-01-29 19:52:04 -07:00
|
|
|
s = gc_status_bit[i];
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
switch (pad->type) {
|
|
|
|
case GC_MULTI2:
|
|
|
|
input_report_key(dev, BTN_THUMB, s & data[5]);
|
|
|
|
/* fall through */
|
|
|
|
|
|
|
|
case GC_MULTI:
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_abs(dev, ABS_X,
|
|
|
|
!(s & data[2]) - !(s & data[3]));
|
|
|
|
input_report_abs(dev, ABS_Y,
|
|
|
|
!(s & data[0]) - !(s & data[1]));
|
2006-01-29 19:52:04 -07:00
|
|
|
input_report_key(dev, BTN_TRIGGER, s & data[4]);
|
2010-02-21 21:54:54 -07:00
|
|
|
input_sync(dev);
|
|
|
|
break;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2006-01-29 19:52:04 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* PSX support
|
|
|
|
*
|
|
|
|
* See documentation at:
|
2010-10-18 03:03:14 -06:00
|
|
|
* http://www.geocities.co.jp/Playtown/2004/psx/ps_eng.txt
|
2005-04-16 16:20:36 -06:00
|
|
|
* http://www.gamesx.com/controldata/psxcont/psxcont.htm
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define GC_PSX_DELAY 25 /* 25 usec */
|
|
|
|
#define GC_PSX_LENGTH 8 /* talk to the controller in bits */
|
|
|
|
#define GC_PSX_BYTES 6 /* the maximum number of bytes to read off the controller */
|
|
|
|
|
|
|
|
#define GC_PSX_MOUSE 1 /* Mouse */
|
|
|
|
#define GC_PSX_NEGCON 2 /* NegCon */
|
|
|
|
#define GC_PSX_NORMAL 4 /* Digital / Analog or Rumble in Digital mode */
|
|
|
|
#define GC_PSX_ANALOG 5 /* Analog in Analog mode / Rumble in Green mode */
|
|
|
|
#define GC_PSX_RUMBLE 7 /* Rumble in Red mode */
|
|
|
|
|
|
|
|
#define GC_PSX_CLOCK 0x04 /* Pin 4 */
|
|
|
|
#define GC_PSX_COMMAND 0x01 /* Pin 2 */
|
|
|
|
#define GC_PSX_POWER 0xf8 /* Pins 5-9 */
|
|
|
|
#define GC_PSX_SELECT 0x02 /* Pin 3 */
|
|
|
|
|
|
|
|
#define GC_PSX_ID(x) ((x) >> 4) /* High nibble is device type */
|
|
|
|
#define GC_PSX_LEN(x) (((x) & 0xf) << 1) /* Low nibble is length in bytes/2 */
|
|
|
|
|
|
|
|
static int gc_psx_delay = GC_PSX_DELAY;
|
|
|
|
module_param_named(psx_delay, gc_psx_delay, uint, 0);
|
|
|
|
MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
|
|
|
|
|
2010-02-21 21:55:09 -07:00
|
|
|
static const short gc_psx_abs[] = {
|
2010-02-21 21:54:28 -07:00
|
|
|
ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y
|
|
|
|
};
|
2010-02-21 21:55:09 -07:00
|
|
|
static const short gc_psx_btn[] = {
|
2010-02-21 21:54:28 -07:00
|
|
|
BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
|
|
|
|
BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR
|
|
|
|
};
|
2010-02-21 21:55:09 -07:00
|
|
|
static const short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* gc_psx_command() writes 8bit command and reads 8bit data from
|
|
|
|
* the psx pad.
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
static void gc_psx_command(struct gc *gc, int b, unsigned char *data)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2010-02-21 21:54:28 -07:00
|
|
|
struct parport *port = gc->pd->port;
|
2005-04-16 16:20:36 -06:00
|
|
|
int i, j, cmd, read;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
memset(data, 0, GC_MAX_DEVICES);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) {
|
|
|
|
cmd = (b & 1) ? GC_PSX_COMMAND : 0;
|
2010-02-21 21:54:28 -07:00
|
|
|
parport_write_data(port, cmd | GC_PSX_POWER);
|
2005-04-16 16:20:36 -06:00
|
|
|
udelay(gc_psx_delay);
|
2010-02-21 21:54:54 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
read = parport_read_status(port) ^ 0x80;
|
2010-02-21 21:54:54 -07:00
|
|
|
|
|
|
|
for (j = 0; j < GC_MAX_DEVICES; j++) {
|
2010-07-20 21:25:35 -06:00
|
|
|
struct gc_pad *pad = &gc->pads[j];
|
2010-02-21 21:54:54 -07:00
|
|
|
|
|
|
|
if (pad->type == GC_PSX || pad->type == GC_DDR)
|
|
|
|
data[j] |= (read & gc_status_bit[j]) ? (1 << i) : 0;
|
|
|
|
}
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
|
|
|
|
udelay(gc_psx_delay);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gc_psx_read_packet() reads a whole psx packet and returns
|
|
|
|
* device identifier code.
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
static void gc_psx_read_packet(struct gc *gc,
|
|
|
|
unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES],
|
2006-01-29 19:52:04 -07:00
|
|
|
unsigned char id[GC_MAX_DEVICES])
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
int i, j, max_len = 0;
|
|
|
|
unsigned long flags;
|
2006-01-29 19:52:04 -07:00
|
|
|
unsigned char data2[GC_MAX_DEVICES];
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
/* Select pad */
|
|
|
|
parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
|
2005-04-16 16:20:36 -06:00
|
|
|
udelay(gc_psx_delay);
|
2010-02-21 21:54:28 -07:00
|
|
|
/* Deselect, begin command */
|
|
|
|
parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER);
|
2005-04-16 16:20:36 -06:00
|
|
|
udelay(gc_psx_delay);
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
gc_psx_command(gc, 0x01, data2); /* Access pad */
|
|
|
|
gc_psx_command(gc, 0x42, id); /* Get device ids */
|
|
|
|
gc_psx_command(gc, 0, data2); /* Dump status */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
/* Find the longest pad */
|
2010-02-21 21:54:54 -07:00
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++) {
|
|
|
|
struct gc_pad *pad = &gc->pads[i];
|
|
|
|
|
|
|
|
if ((pad->type == GC_PSX || pad->type == GC_DDR) &&
|
2010-02-21 21:54:28 -07:00
|
|
|
GC_PSX_LEN(id[i]) > max_len &&
|
|
|
|
GC_PSX_LEN(id[i]) <= GC_PSX_BYTES) {
|
2005-04-16 16:20:36 -06:00
|
|
|
max_len = GC_PSX_LEN(id[i]);
|
2010-02-21 21:54:28 -07:00
|
|
|
}
|
2010-02-21 21:54:54 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
/* Read in all the data */
|
|
|
|
for (i = 0; i < max_len; i++) {
|
2005-04-16 16:20:36 -06:00
|
|
|
gc_psx_command(gc, 0, data2);
|
2006-01-29 19:52:04 -07:00
|
|
|
for (j = 0; j < GC_MAX_DEVICES; j++)
|
2005-04-16 16:20:36 -06:00
|
|
|
data[j][i] = data2[j];
|
|
|
|
}
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
|
|
|
|
parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
/* Set id's to the real value */
|
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++)
|
2005-04-16 16:20:36 -06:00
|
|
|
id[i] = GC_PSX_ID(id[i]);
|
|
|
|
}
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
static void gc_psx_report_one(struct gc_pad *pad, unsigned char psx_type,
|
2010-02-21 21:54:28 -07:00
|
|
|
unsigned char *data)
|
2006-01-29 19:52:04 -07:00
|
|
|
{
|
2010-02-21 21:54:54 -07:00
|
|
|
struct input_dev *dev = pad->dev;
|
2010-02-21 21:54:28 -07:00
|
|
|
int i;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
switch (psx_type) {
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_PSX_RUMBLE:
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, BTN_THUMBL, ~data[0] & 0x04);
|
|
|
|
input_report_key(dev, BTN_THUMBR, ~data[0] & 0x02);
|
2017-11-10 11:23:59 -07:00
|
|
|
/* fall through */
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_PSX_NEGCON:
|
|
|
|
case GC_PSX_ANALOG:
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (pad->type == GC_DDR) {
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
input_report_key(dev, gc_psx_ddr_btn[i],
|
|
|
|
~data[0] & (0x10 << i));
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
input_report_abs(dev, gc_psx_abs[i + 2],
|
|
|
|
data[i + 2]);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:31 -07:00
|
|
|
input_report_abs(dev, ABS_X,
|
|
|
|
!!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127);
|
|
|
|
input_report_abs(dev, ABS_Y,
|
|
|
|
!!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127);
|
2010-02-21 21:54:28 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, BTN_START, ~data[0] & 0x08);
|
|
|
|
input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_sync(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_PSX_NORMAL:
|
2010-02-21 21:54:54 -07:00
|
|
|
|
|
|
|
if (pad->type == GC_DDR) {
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
input_report_key(dev, gc_psx_ddr_btn[i],
|
|
|
|
~data[0] & (0x10 << i));
|
|
|
|
} else {
|
2010-02-21 21:54:31 -07:00
|
|
|
input_report_abs(dev, ABS_X,
|
|
|
|
!!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127);
|
|
|
|
input_report_abs(dev, ABS_Y,
|
|
|
|
!!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
/*
|
|
|
|
* For some reason if the extra axes are left unset
|
|
|
|
* they drift.
|
|
|
|
* for (i = 0; i < 4; i++)
|
|
|
|
input_report_abs(dev, gc_psx_abs[i + 2], 128);
|
|
|
|
* This needs to be debugged properly,
|
|
|
|
* maybe fuzz processing needs to be done
|
|
|
|
* in input_sync()
|
|
|
|
* --vojtech
|
|
|
|
*/
|
|
|
|
}
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_report_key(dev, BTN_START, ~data[0] & 0x08);
|
|
|
|
input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
input_sync(dev);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
default: /* not a pad, ignore */
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
static void gc_psx_process_packet(struct gc *gc)
|
|
|
|
{
|
|
|
|
unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES];
|
|
|
|
unsigned char id[GC_MAX_DEVICES];
|
2010-02-21 21:54:54 -07:00
|
|
|
struct gc_pad *pad;
|
2010-02-21 21:54:28 -07:00
|
|
|
int i;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
gc_psx_read_packet(gc, data, id);
|
2006-01-29 19:52:04 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++) {
|
2010-02-21 21:54:54 -07:00
|
|
|
pad = &gc->pads[i];
|
|
|
|
if (pad->type == GC_PSX || pad->type == GC_DDR)
|
|
|
|
gc_psx_report_one(pad, id[i], data[i]);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2006-01-29 19:52:04 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
2006-01-29 19:52:04 -07:00
|
|
|
* gc_timer() initiates reads of console pads data.
|
2005-04-16 16:20:36 -06:00
|
|
|
*/
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 15:43:17 -06:00
|
|
|
static void gc_timer(struct timer_list *t)
|
2006-01-29 19:52:04 -07:00
|
|
|
{
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 15:43:17 -06:00
|
|
|
struct gc *gc = from_timer(gc, t, timer);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
/*
|
|
|
|
* N64 pads - must be read first, any read confuses them for 200 us
|
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pad_count[GC_N64])
|
2006-01-29 19:52:04 -07:00
|
|
|
gc_n64_process_packet(gc);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
/*
|
2006-04-01 22:10:05 -07:00
|
|
|
* NES and SNES pads or mouse
|
2006-01-29 19:52:04 -07:00
|
|
|
*/
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pad_count[GC_NES] ||
|
|
|
|
gc->pad_count[GC_SNES] ||
|
|
|
|
gc->pad_count[GC_SNESMOUSE]) {
|
2006-01-29 19:52:04 -07:00
|
|
|
gc_nes_process_packet(gc);
|
2010-02-21 21:54:54 -07:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Multi and Multi2 joysticks
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pad_count[GC_MULTI] || gc->pad_count[GC_MULTI2])
|
2006-01-29 19:52:04 -07:00
|
|
|
gc_multi_process_packet(gc);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* PSX controllers
|
|
|
|
*/
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pad_count[GC_PSX] || gc->pad_count[GC_DDR])
|
2006-01-29 19:52:04 -07:00
|
|
|
gc_psx_process_packet(gc);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int gc_open(struct input_dev *dev)
|
|
|
|
{
|
2007-04-11 23:34:14 -06:00
|
|
|
struct gc *gc = input_get_drvdata(dev);
|
2005-05-29 01:29:52 -06:00
|
|
|
int err;
|
|
|
|
|
2006-02-18 22:22:30 -07:00
|
|
|
err = mutex_lock_interruptible(&gc->mutex);
|
2005-05-29 01:29:52 -06:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!gc->used++) {
|
|
|
|
parport_claim(gc->pd);
|
|
|
|
parport_write_control(gc->pd->port, 0x04);
|
|
|
|
mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
|
|
|
|
}
|
2005-05-29 01:29:52 -06:00
|
|
|
|
2006-02-18 22:22:30 -07:00
|
|
|
mutex_unlock(&gc->mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gc_close(struct input_dev *dev)
|
|
|
|
{
|
2007-04-11 23:34:14 -06:00
|
|
|
struct gc *gc = input_get_drvdata(dev);
|
2005-05-29 01:29:52 -06:00
|
|
|
|
2006-02-18 22:22:30 -07:00
|
|
|
mutex_lock(&gc->mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
if (!--gc->used) {
|
2005-05-29 01:29:52 -06:00
|
|
|
del_timer_sync(&gc->timer);
|
2005-04-16 16:20:36 -06:00
|
|
|
parport_write_control(gc->pd->port, 0x00);
|
|
|
|
parport_release(gc->pd);
|
|
|
|
}
|
2006-02-18 22:22:30 -07:00
|
|
|
mutex_unlock(&gc->mutex);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static int gc_setup_pad(struct gc *gc, int idx, int pad_type)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2010-02-21 21:54:54 -07:00
|
|
|
struct gc_pad *pad = &gc->pads[idx];
|
2005-09-15 01:01:52 -06:00
|
|
|
struct input_dev *input_dev;
|
|
|
|
int i;
|
2010-02-21 21:53:55 -07:00
|
|
|
int err;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-03-05 01:31:33 -07:00
|
|
|
if (pad_type < 1 || pad_type >= GC_MAX) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("Pad type %d unknown\n", pad_type);
|
2005-09-15 01:01:52 -06:00
|
|
|
return -EINVAL;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
pad->dev = input_dev = input_allocate_device();
|
2005-09-15 01:01:52 -06:00
|
|
|
if (!input_dev) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("Not enough memory for input device\n");
|
2005-09-15 01:01:52 -06:00
|
|
|
return -ENOMEM;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
pad->type = pad_type;
|
|
|
|
|
|
|
|
snprintf(pad->phys, sizeof(pad->phys),
|
|
|
|
"%s/input%d", gc->pd->port->name, idx);
|
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
input_dev->name = gc_names[pad_type];
|
2010-02-21 21:54:54 -07:00
|
|
|
input_dev->phys = pad->phys;
|
2005-09-15 01:01:52 -06:00
|
|
|
input_dev->id.bustype = BUS_PARPORT;
|
|
|
|
input_dev->id.vendor = 0x0001;
|
|
|
|
input_dev->id.product = pad_type;
|
|
|
|
input_dev->id.version = 0x0100;
|
2007-04-11 23:34:14 -06:00
|
|
|
|
|
|
|
input_set_drvdata(input_dev, gc);
|
2005-09-15 01:01:52 -06:00
|
|
|
|
|
|
|
input_dev->open = gc_open;
|
|
|
|
input_dev->close = gc_close;
|
|
|
|
|
2006-04-01 22:10:05 -07:00
|
|
|
if (pad_type != GC_SNESMOUSE) {
|
2007-10-19 00:40:32 -06:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
|
2005-09-15 01:01:52 -06:00
|
|
|
|
2006-04-01 22:10:05 -07:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
input_set_abs_params(input_dev, ABS_X + i, -1, 1, 0, 0);
|
|
|
|
} else
|
2007-10-19 00:40:32 -06:00
|
|
|
input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
|
2005-09-15 01:01:52 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
gc->pad_count[pad_type]++;
|
2005-09-15 01:01:52 -06:00
|
|
|
|
|
|
|
switch (pad_type) {
|
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_N64:
|
|
|
|
for (i = 0; i < 10; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, gc_n64_btn[i]);
|
2006-04-01 22:10:05 -07:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
|
|
|
|
input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
|
|
|
|
}
|
2005-09-15 01:01:52 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
err = gc_n64_init_ff(input_dev, idx);
|
|
|
|
if (err) {
|
2017-03-17 18:15:38 -06:00
|
|
|
pr_warn("Failed to initiate rumble for N64 device %d\n",
|
|
|
|
idx);
|
2010-02-21 21:54:54 -07:00
|
|
|
goto err_free_dev;
|
2010-02-21 21:54:28 -07:00
|
|
|
}
|
2005-09-15 01:01:52 -06:00
|
|
|
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_SNESMOUSE:
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, BTN_LEFT);
|
|
|
|
input_set_capability(input_dev, EV_KEY, BTN_RIGHT);
|
|
|
|
input_set_capability(input_dev, EV_REL, REL_X);
|
|
|
|
input_set_capability(input_dev, EV_REL, REL_Y);
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_SNES:
|
|
|
|
for (i = 4; i < 8; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, gc_snes_btn[i]);
|
2017-11-10 11:23:59 -07:00
|
|
|
/* fall through */
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_NES:
|
|
|
|
for (i = 0; i < 4; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, gc_snes_btn[i]);
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_MULTI2:
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, BTN_THUMB);
|
2017-11-10 11:23:59 -07:00
|
|
|
/* fall through */
|
2010-02-21 21:54:28 -07:00
|
|
|
case GC_MULTI:
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, BTN_TRIGGER);
|
|
|
|
/* fall through */
|
2010-02-21 21:54:28 -07:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_PSX:
|
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
input_set_abs_params(input_dev,
|
|
|
|
gc_psx_abs[i], 4, 252, 0, 2);
|
|
|
|
for (i = 0; i < 12; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, gc_psx_btn[i]);
|
|
|
|
break;
|
2010-02-21 21:54:28 -07:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GC_DDR:
|
|
|
|
for (i = 0; i < 4; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY,
|
|
|
|
gc_psx_ddr_btn[i]);
|
2010-02-21 21:54:28 -07:00
|
|
|
for (i = 0; i < 12; i++)
|
2018-05-08 16:21:21 -06:00
|
|
|
input_set_capability(input_dev, EV_KEY, gc_psx_btn[i]);
|
2010-02-21 21:54:28 -07:00
|
|
|
|
|
|
|
break;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2005-05-29 01:29:52 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
err = input_register_device(pad->dev);
|
|
|
|
if (err)
|
|
|
|
goto err_free_dev;
|
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
return 0;
|
2010-02-21 21:54:54 -07:00
|
|
|
|
|
|
|
err_free_dev:
|
|
|
|
input_free_device(pad->dev);
|
|
|
|
pad->dev = NULL;
|
|
|
|
return err;
|
2005-09-15 01:01:52 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static void gc_attach(struct parport *pp)
|
2005-09-15 01:01:52 -06:00
|
|
|
{
|
|
|
|
struct gc *gc;
|
|
|
|
struct pardevice *pd;
|
2015-10-05 18:22:58 -06:00
|
|
|
int i, port_idx;
|
2010-02-21 21:54:54 -07:00
|
|
|
int count = 0;
|
2015-09-29 17:03:43 -06:00
|
|
|
int *pads, n_pads;
|
|
|
|
struct pardev_cb gc_parport_cb;
|
|
|
|
|
2015-10-05 18:22:58 -06:00
|
|
|
for (port_idx = 0; port_idx < GC_MAX_PORTS; port_idx++) {
|
|
|
|
if (gc_cfg[port_idx].nargs == 0 || gc_cfg[port_idx].args[0] < 0)
|
2015-09-29 17:03:43 -06:00
|
|
|
continue;
|
|
|
|
|
2015-10-05 18:22:58 -06:00
|
|
|
if (gc_cfg[port_idx].args[0] == pp->number)
|
2015-09-29 17:03:43 -06:00
|
|
|
break;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-10-05 18:22:58 -06:00
|
|
|
if (port_idx == GC_MAX_PORTS) {
|
2015-09-29 17:03:43 -06:00
|
|
|
pr_debug("Not using parport%d.\n", pp->number);
|
|
|
|
return;
|
2005-09-15 01:01:52 -06:00
|
|
|
}
|
2015-10-05 18:22:58 -06:00
|
|
|
pads = gc_cfg[port_idx].args + 1;
|
|
|
|
n_pads = gc_cfg[port_idx].nargs - 1;
|
2015-09-29 17:03:43 -06:00
|
|
|
|
2015-11-17 10:33:29 -07:00
|
|
|
memset(&gc_parport_cb, 0, sizeof(gc_parport_cb));
|
2015-09-29 17:03:43 -06:00
|
|
|
gc_parport_cb.flags = PARPORT_FLAG_EXCL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-10-05 18:22:58 -06:00
|
|
|
pd = parport_register_dev_model(pp, "gamecon", &gc_parport_cb,
|
|
|
|
port_idx);
|
2005-09-15 01:01:52 -06:00
|
|
|
if (!pd) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("parport busy already - lp.o loaded?\n");
|
2015-09-29 17:03:43 -06:00
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
|
|
|
|
if (!gc) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("Not enough memory\n");
|
2005-09-15 01:01:52 -06:00
|
|
|
goto err_unreg_pardev;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-02-18 22:22:30 -07:00
|
|
|
mutex_init(&gc->mutex);
|
2005-09-15 01:01:52 -06:00
|
|
|
gc->pd = pd;
|
2015-09-29 17:03:43 -06:00
|
|
|
gc->parportno = pp->number;
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 15:43:17 -06:00
|
|
|
timer_setup(&gc->timer, gc_timer, 0);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-29 19:52:04 -07:00
|
|
|
for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) {
|
2005-09-15 01:01:52 -06:00
|
|
|
if (!pads[i])
|
2005-04-16 16:20:36 -06:00
|
|
|
continue;
|
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
if (gc_setup_pad(gc, i, pads[i]))
|
2006-01-29 19:52:11 -07:00
|
|
|
goto err_unreg_devs;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
count++;
|
2005-09-15 01:01:52 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2010-02-21 21:54:54 -07:00
|
|
|
if (count == 0) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("No valid devices specified\n");
|
2005-09-15 01:01:52 -06:00
|
|
|
goto err_free_gc;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-10-05 18:22:58 -06:00
|
|
|
gc_base[port_idx] = gc;
|
2015-09-29 17:03:43 -06:00
|
|
|
return;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-29 19:52:11 -07:00
|
|
|
err_unreg_devs:
|
2005-09-15 01:01:52 -06:00
|
|
|
while (--i >= 0)
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pads[i].dev)
|
|
|
|
input_unregister_device(gc->pads[i].dev);
|
2005-09-15 01:01:52 -06:00
|
|
|
err_free_gc:
|
|
|
|
kfree(gc);
|
|
|
|
err_unreg_pardev:
|
|
|
|
parport_unregister_device(pd);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static void gc_detach(struct parport *port)
|
2005-09-15 01:01:52 -06:00
|
|
|
{
|
|
|
|
int i;
|
2015-09-29 17:03:43 -06:00
|
|
|
struct gc *gc;
|
|
|
|
|
|
|
|
for (i = 0; i < GC_MAX_PORTS; i++) {
|
|
|
|
if (gc_base[i] && gc_base[i]->parportno == port->number)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == GC_MAX_PORTS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gc = gc_base[i];
|
|
|
|
gc_base[i] = NULL;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
for (i = 0; i < GC_MAX_DEVICES; i++)
|
2010-02-21 21:54:54 -07:00
|
|
|
if (gc->pads[i].dev)
|
|
|
|
input_unregister_device(gc->pads[i].dev);
|
2005-09-15 01:01:52 -06:00
|
|
|
parport_unregister_device(gc->pd);
|
|
|
|
kfree(gc);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
static struct parport_driver gc_parport_driver = {
|
|
|
|
.name = "gamecon",
|
|
|
|
.match_port = gc_attach,
|
|
|
|
.detach = gc_detach,
|
|
|
|
.devmodel = true,
|
|
|
|
};
|
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
static int __init gc_init(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int have_dev = 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
for (i = 0; i < GC_MAX_PORTS; i++) {
|
2007-05-02 22:52:51 -06:00
|
|
|
if (gc_cfg[i].nargs == 0 || gc_cfg[i].args[0] < 0)
|
2005-09-15 01:01:52 -06:00
|
|
|
continue;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-05-02 22:52:51 -06:00
|
|
|
if (gc_cfg[i].nargs < 2) {
|
2010-02-21 21:55:31 -07:00
|
|
|
pr_err("at least one device must be specified\n");
|
2015-09-29 17:03:43 -06:00
|
|
|
return -EINVAL;
|
2005-09-15 01:01:52 -06:00
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2005-09-15 01:01:52 -06:00
|
|
|
have_dev = 1;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
if (!have_dev)
|
|
|
|
return -ENODEV;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2015-09-29 17:03:43 -06:00
|
|
|
return parport_register_driver(&gc_parport_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit gc_exit(void)
|
|
|
|
{
|
2015-09-29 17:03:43 -06:00
|
|
|
parport_unregister_driver(&gc_parport_driver);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(gc_init);
|
|
|
|
module_exit(gc_exit);
|