drivers/input/joystick/grip_mp.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/grip_mp.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/grip_mp.c- Extension
.c- Size
- 17039 bytes
- Lines
- 692
- Domain
- Driver Families
- Bucket
- drivers/input
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/module.hlinux/slab.hlinux/gameport.hlinux/input.hlinux/delay.hlinux/proc_fs.hlinux/jiffies.h
Detected Declarations
struct grip_portstruct grip_mpfunction bit_parityfunction poll_untilfunction mp_iofunction mp_iofunction dig_mode_startfunction get_and_decode_packetfunction slots_validfunction multiport_initfunction report_slotfunction grip_pollfunction grip_openfunction grip_closefunction register_slotfunction grip_connectfunction grip_disconnect
Annotated Snippet
struct grip_port {
struct input_dev *dev;
int mode;
int registered;
/* individual gamepad states */
int buttons;
int xaxes;
int yaxes;
int dirty; /* has the state been updated? */
};
struct grip_mp {
struct gameport *gameport;
struct grip_port *port[GRIP_MAX_PORTS];
int reads;
int bads;
};
/*
* Multiport packet interpretation
*/
#define PACKET_FULL 0x80000000 /* packet is full */
#define PACKET_IO_FAST 0x40000000 /* 3 bits per gameport read */
#define PACKET_IO_SLOW 0x20000000 /* 1 bit per gameport read */
#define PACKET_MP_MORE 0x04000000 /* multiport wants to send more */
#define PACKET_MP_DONE 0x02000000 /* multiport done sending */
/*
* Packet status code interpretation
*/
#define IO_GOT_PACKET 0x0100 /* Got a packet */
#define IO_MODE_FAST 0x0200 /* Used 3 data bits per gameport read */
#define IO_SLOT_CHANGE 0x0800 /* Multiport physical slot status changed */
#define IO_DONE 0x1000 /* Multiport is done sending packets */
#define IO_RETRY 0x4000 /* Try again later to get packet */
#define IO_RESET 0x8000 /* Force multiport to resend all packets */
/*
* Gamepad configuration data. Other 9-pin digital joystick devices
* may work with the multiport, so this may not be an exhaustive list!
* Commodore 64 joystick remains untested.
*/
#define GRIP_INIT_DELAY 2000 /* 2 ms */
#define GRIP_MODE_NONE 0
#define GRIP_MODE_RESET 1
#define GRIP_MODE_GP 2
#define GRIP_MODE_C64 3
static const int grip_btn_gp[] = { BTN_TR, BTN_TL, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, -1 };
static const int grip_btn_c64[] = { BTN_JOYSTICK, -1 };
static const int grip_abs_gp[] = { ABS_X, ABS_Y, -1 };
static const int grip_abs_c64[] = { ABS_X, ABS_Y, -1 };
static const int *grip_abs[] = { NULL, NULL, grip_abs_gp, grip_abs_c64 };
static const int *grip_btn[] = { NULL, NULL, grip_btn_gp, grip_btn_c64 };
static const char *grip_name[] = { NULL, NULL, "Gravis Grip Pad", "Commodore 64 Joystick" };
static const int init_seq[] = {
1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1 };
/* Maps multiport directional values to X,Y axis values (each axis encoded in 3 bits) */
static const int axis_map[] = { 5, 9, 1, 5, 6, 10, 2, 6, 4, 8, 0, 4, 5, 9, 1, 5 };
static int register_slot(int i, struct grip_mp *grip);
/*
* Returns whether an odd or even number of bits are on in pkt.
*/
static int bit_parity(u32 pkt)
{
int x = pkt ^ (pkt >> 16);
x ^= x >> 8;
x ^= x >> 4;
x ^= x >> 2;
x ^= x >> 1;
return x & 1;
}
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/gameport.h`, `linux/input.h`, `linux/delay.h`, `linux/proc_fs.h`, `linux/jiffies.h`.
- Detected declarations: `struct grip_port`, `struct grip_mp`, `function bit_parity`, `function poll_until`, `function mp_io`, `function mp_io`, `function dig_mode_start`, `function get_and_decode_packet`, `function slots_valid`, `function multiport_init`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.