drivers/input/joystick/sidewinder.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/sidewinder.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/sidewinder.c- Extension
.c- Size
- 20807 bytes
- Lines
- 811
- 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/module.hlinux/slab.hlinux/input.hlinux/gameport.hlinux/jiffies.hlinux/string_choices.h
Detected Declarations
struct swfunction sw_read_packetfunction sw_get_bitsfunction sw_init_digitalfunction sw_parityfunction sw_ccheckfunction sw_parsefunction sw_readfunction sw_pollfunction sw_openfunction sw_closefunction sw_print_packetfunction sw_3dp_idfunction sw_guess_modefunction sw_connectfunction sw_disconnect
Annotated Snippet
struct sw {
struct gameport *gameport;
struct input_dev *dev[4];
char name[64];
char phys[4][32];
int length;
int type;
int bits;
int number;
int fail;
int ok;
int reads;
int bads;
};
/*
* sw_read_packet() is a function which reads either a data packet, or an
* identification packet from a SideWinder joystick. The protocol is very,
* very, very braindamaged. Microsoft patented it in US patent #5628686.
*/
static int sw_read_packet(struct gameport *gameport, unsigned char *buf, int length, int id)
{
unsigned long flags;
int timeout, bitout, sched, i, kick, start, strobe;
unsigned char pending, u, v;
i = -id; /* Don't care about data, only want ID */
timeout = id ? gameport_time(gameport, SW_TIMEOUT * 1000) : 0; /* Set up global timeout for ID packet */
kick = id ? gameport_time(gameport, SW_KICK) : 0; /* Set up kick timeout for ID packet */
start = gameport_time(gameport, SW_START);
strobe = gameport_time(gameport, SW_STROBE);
bitout = start;
pending = 0;
sched = 0;
local_irq_save(flags); /* Quiet, please */
gameport_trigger(gameport); /* Trigger */
v = gameport_read(gameport);
do {
bitout--;
u = v;
v = gameport_read(gameport);
} while (!(~v & u & 0x10) && (bitout > 0)); /* Wait for first falling edge on clock */
if (bitout > 0)
bitout = strobe; /* Extend time if not timed out */
while ((timeout > 0 || bitout > 0) && (i < length)) {
timeout--;
bitout--; /* Decrement timers */
sched--;
u = v;
v = gameport_read(gameport);
if ((~u & v & 0x10) && (bitout > 0)) { /* Rising edge on clock - data bit */
if (i >= 0) /* Want this data */
buf[i] = v >> 5; /* Store it */
i++; /* Advance index */
bitout = strobe; /* Extend timeout for next bit */
}
if (kick && (~v & u & 0x01)) { /* Falling edge on axis 0 */
sched = kick; /* Schedule second trigger */
kick = 0; /* Don't schedule next time on falling edge */
pending = 1; /* Mark schedule */
}
if (pending && sched < 0 && (i > -SW_END)) { /* Second trigger time */
gameport_trigger(gameport); /* Trigger */
bitout = start; /* Long bit timeout */
pending = 0; /* Unmark schedule */
timeout = 0; /* Switch from global to bit timeouts */
}
}
local_irq_restore(flags); /* Done - relax */
#ifdef SW_DEBUG_DATA
{
int j;
printk(KERN_DEBUG "sidewinder.c: Read %d triplets. [", i);
for (j = 0; j < i; j++) printk("%d", buf[j]);
printk("]\n");
}
#endif
Annotation
- Immediate include surface: `linux/delay.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/input.h`, `linux/gameport.h`, `linux/jiffies.h`, `linux/string_choices.h`.
- Detected declarations: `struct sw`, `function sw_read_packet`, `function sw_get_bits`, `function sw_init_digital`, `function sw_parity`, `function sw_ccheck`, `function sw_parse`, `function sw_read`, `function sw_poll`, `function sw_open`.
- 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.