drivers/input/joystick/gf2k.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/gf2k.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/gf2k.c- Extension
.c- Size
- 8808 bytes
- Lines
- 359
- 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/delay.hlinux/kernel.hlinux/slab.hlinux/module.hlinux/input.hlinux/gameport.hlinux/jiffies.h
Detected Declarations
struct gf2kfunction gf2k_read_packetfunction gf2k_trigger_seqfunction js_sw_get_bitsfunction gf2k_readfunction gf2k_pollfunction gf2k_openfunction gf2k_closefunction gf2k_connectfunction gf2k_disconnect
Annotated Snippet
struct gf2k {
struct gameport *gameport;
struct input_dev *dev;
int reads;
int bads;
unsigned char id;
unsigned char length;
char phys[32];
};
/*
* gf2k_read_packet() reads a Genius Flight2000 packet.
*/
static int gf2k_read_packet(struct gameport *gameport, int length, char *data)
{
unsigned char u, v;
int i;
unsigned int t, p;
unsigned long flags;
t = gameport_time(gameport, GF2K_START);
p = gameport_time(gameport, GF2K_STROBE);
i = 0;
local_irq_save(flags);
gameport_trigger(gameport);
v = gameport_read(gameport);
while (t > 0 && i < length) {
t--; u = v;
v = gameport_read(gameport);
if (v & ~u & 0x10) {
data[i++] = v >> 5;
t = p;
}
}
local_irq_restore(flags);
return i;
}
/*
* gf2k_trigger_seq() initializes a Genius Flight2000 joystick
* into digital mode.
*/
static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
{
unsigned long flags;
int i, t;
local_irq_save(flags);
i = 0;
do {
gameport_trigger(gameport);
t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
while ((gameport_read(gameport) & 1) && t) t--;
udelay(seq[i]);
} while (seq[++i]);
gameport_trigger(gameport);
local_irq_restore(flags);
}
/*
* js_sw_get_bits() composes bits from the triplet buffer into a __u64.
* Parameter 'pos' is bit number inside packet where to start at, 'num' is number
* of bits to be read, 'shift' is offset in the resulting __u64 to start at, bits
* is number of bits per triplet.
*/
#define GB(p,n,s) gf2k_get_bits(data, p, n, s)
static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
{
__u64 data = 0;
int i;
for (i = 0; i < num / 3 + 2; i++)
data |= buf[pos / 3 + i] << (i * 3);
data >>= pos % 3;
data &= (1 << num) - 1;
data <<= shift;
Annotation
- Immediate include surface: `linux/delay.h`, `linux/kernel.h`, `linux/slab.h`, `linux/module.h`, `linux/input.h`, `linux/gameport.h`, `linux/jiffies.h`.
- Detected declarations: `struct gf2k`, `function gf2k_read_packet`, `function gf2k_trigger_seq`, `function js_sw_get_bits`, `function gf2k_read`, `function gf2k_poll`, `function gf2k_open`, `function gf2k_close`, `function gf2k_connect`, `function gf2k_disconnect`.
- 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.