drivers/input/joystick/xpad.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/xpad.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/xpad.c- Extension
.c- Size
- 80993 bytes
- Lines
- 2320
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/bits.hlinux/kernel.hlinux/input.hlinux/rcupdate.hlinux/slab.hlinux/stat.hlinux/module.hlinux/usb/input.hlinux/usb/quirks.hlinux/leds.hlinux/idr.h
Detected Declarations
struct xboxone_init_packetstruct xpad_output_packetstruct usb_xpadstruct xpad_ledfunction xpad_process_packetfunction xpad360_process_packetfunction xpad_presence_workfunction xpad360w_process_packetfunction xpadone_process_packetfunction xpad_irq_infunction xpad_prepare_next_init_packetfunction xpad_prepare_next_out_packetfunction xpad_try_sending_next_out_packetfunction xpad_irq_outfunction xpad_init_outputfunction xpad_stop_outputfunction xpad_deinit_outputfunction xpad_inquiry_pad_presencefunction xpad_start_xbox_onefunction xpadone_ack_mode_reportfunction xpad_play_effectfunction xpad_init_fffunction xpad_init_fffunction xpad_send_led_commandfunction xpad_identify_controllerfunction xpad_led_setfunction xpad_led_probefunction xpad_led_disconnectfunction xpad_led_probefunction xpad_led_disconnectfunction xpad_stop_inputfunction xpad360w_poweroff_controllerfunction xpad360w_start_inputfunction xpad360w_stop_inputfunction xpad_openfunction xpad_closefunction xpad_set_up_absfunction xpad_deinit_inputfunction xpad_init_inputfunction xpad_probefunction xpad_disconnectfunction xpad_suspendfunction xpad_resume
Annotated Snippet
struct xboxone_init_packet {
u16 idVendor;
u16 idProduct;
const u8 *data;
u8 len;
};
#define XBOXONE_INIT_PKT(_vid, _pid, _data) \
{ \
.idVendor = (_vid), \
.idProduct = (_pid), \
.data = (_data), \
.len = ARRAY_SIZE(_data), \
}
/*
* starting with xbox one, the game input protocol is used
* magic numbers are taken from
* - https://github.com/xpadneo/gip-dissector/blob/main/src/gip-dissector.lua
* - https://github.com/medusalix/xone/blob/master/bus/protocol.c
*/
#define GIP_CMD_ACK 0x01
#define GIP_CMD_ANNOUNCE 0x02
#define GIP_CMD_IDENTIFY 0x04
#define GIP_CMD_POWER 0x05
#define GIP_CMD_AUTHENTICATE 0x06
#define GIP_CMD_VIRTUAL_KEY 0x07
#define GIP_CMD_RUMBLE 0x09
#define GIP_CMD_LED 0x0a
#define GIP_CMD_FIRMWARE 0x0c
#define GIP_CMD_INPUT 0x20
#define GIP_SEQ0 0x00
#define GIP_OPT_ACK 0x10
#define GIP_OPT_INTERNAL 0x20
/*
* length of the command payload encoded with
* https://en.wikipedia.org/wiki/LEB128
* which is a no-op for N < 128
*/
#define GIP_PL_LEN(N) (N)
/*
* payload specific defines
*/
#define GIP_PWR_ON 0x00
#define GIP_LED_ON 0x01
#define GIP_MOTOR_R BIT(0)
#define GIP_MOTOR_L BIT(1)
#define GIP_MOTOR_RT BIT(2)
#define GIP_MOTOR_LT BIT(3)
#define GIP_MOTOR_ALL (GIP_MOTOR_R | GIP_MOTOR_L | GIP_MOTOR_RT | GIP_MOTOR_LT)
#define GIP_WIRED_INTF_DATA 0
#define GIP_WIRED_INTF_AUDIO 1
/*
* This packet is required for all Xbox One pads with 2015
* or later firmware installed (or present from the factory).
*/
static const u8 xboxone_power_on[] = {
GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, GIP_PL_LEN(1), GIP_PWR_ON
};
/*
* This packet is required for Xbox One S (0x045e:0x02ea)
* and Xbox One Elite Series 2 (0x045e:0x0b00) pads to
* initialize the controller that was previously used in
* Bluetooth mode.
*/
static const u8 xboxone_s_init[] = {
GIP_CMD_POWER, GIP_OPT_INTERNAL, GIP_SEQ0, 0x0f, 0x06
};
/*
* This packet is required to get additional input data
* from Xbox One Elite Series 2 (0x045e:0x0b00) pads.
* We mostly do this right now to get paddle data
*/
static const u8 extra_input_packet_init[] = {
0x4d, 0x10, 0x01, 0x02, 0x07, 0x00
};
/*
* This packet is required for the Titanfall 2 Xbox One pads
* (0x0e6f:0x0165) to finish initialization and for Hori pads
* (0x0f0d:0x0067) to make the analog sticks work.
Annotation
- Immediate include surface: `linux/bits.h`, `linux/kernel.h`, `linux/input.h`, `linux/rcupdate.h`, `linux/slab.h`, `linux/stat.h`, `linux/module.h`, `linux/usb/input.h`.
- Detected declarations: `struct xboxone_init_packet`, `struct xpad_output_packet`, `struct usb_xpad`, `struct xpad_led`, `function xpad_process_packet`, `function xpad360_process_packet`, `function xpad_presence_work`, `function xpad360w_process_packet`, `function xpadone_process_packet`, `function xpad_irq_in`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.