drivers/input/joystick/adafruit-seesaw.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/adafruit-seesaw.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/adafruit-seesaw.c- Extension
.c- Size
- 8359 bytes
- Lines
- 331
- 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/unaligned.hlinux/bits.hlinux/delay.hlinux/i2c.hlinux/input.hlinux/input/sparse-keymap.hlinux/kernel.hlinux/module.h
Detected Declarations
struct seesaw_gamepadstruct seesaw_datafunction seesaw_register_readfunction seesaw_register_write_u8function seesaw_register_write_u32function seesaw_read_datafunction seesaw_openfunction seesaw_pollfunction for_each_set_bitfunction seesaw_probe
Annotated Snippet
struct seesaw_gamepad {
struct input_dev *input_dev;
struct i2c_client *i2c_client;
u32 button_state;
};
struct seesaw_data {
u16 x;
u16 y;
u32 button_state;
};
static const struct key_entry seesaw_buttons_new[] = {
{ KE_KEY, SEESAW_BUTTON_A, .keycode = BTN_SOUTH },
{ KE_KEY, SEESAW_BUTTON_B, .keycode = BTN_EAST },
{ KE_KEY, SEESAW_BUTTON_X, .keycode = BTN_NORTH },
{ KE_KEY, SEESAW_BUTTON_Y, .keycode = BTN_WEST },
{ KE_KEY, SEESAW_BUTTON_START, .keycode = BTN_START },
{ KE_KEY, SEESAW_BUTTON_SELECT, .keycode = BTN_SELECT },
{ KE_END, 0 }
};
static int seesaw_register_read(struct i2c_client *client, u16 reg, void *buf,
int count)
{
__be16 register_buf = cpu_to_be16(reg);
struct i2c_msg message_buf[2] = {
{
.addr = client->addr,
.flags = client->flags,
.len = sizeof(register_buf),
.buf = (u8 *)®ister_buf,
},
{
.addr = client->addr,
.flags = client->flags | I2C_M_RD,
.len = count,
.buf = (u8 *)buf,
},
};
int ret;
ret = i2c_transfer(client->adapter, message_buf,
ARRAY_SIZE(message_buf));
if (ret < 0)
return ret;
return 0;
}
static int seesaw_register_write_u8(struct i2c_client *client, u16 reg,
u8 value)
{
u8 write_buf[sizeof(reg) + sizeof(value)];
int ret;
put_unaligned_be16(reg, write_buf);
write_buf[sizeof(reg)] = value;
ret = i2c_master_send(client, write_buf, sizeof(write_buf));
if (ret < 0)
return ret;
return 0;
}
static int seesaw_register_write_u32(struct i2c_client *client, u16 reg,
u32 value)
{
u8 write_buf[sizeof(reg) + sizeof(value)];
int ret;
put_unaligned_be16(reg, write_buf);
put_unaligned_be32(value, write_buf + sizeof(reg));
ret = i2c_master_send(client, write_buf, sizeof(write_buf));
if (ret < 0)
return ret;
return 0;
}
static int seesaw_read_data(struct i2c_client *client, struct seesaw_data *data)
{
__be16 adc_data;
__be32 read_buf;
int err;
err = seesaw_register_read(client, SEESAW_GPIO_BULK,
&read_buf, sizeof(read_buf));
if (err)
Annotation
- Immediate include surface: `linux/unaligned.h`, `linux/bits.h`, `linux/delay.h`, `linux/i2c.h`, `linux/input.h`, `linux/input/sparse-keymap.h`, `linux/kernel.h`, `linux/module.h`.
- Detected declarations: `struct seesaw_gamepad`, `struct seesaw_data`, `function seesaw_register_read`, `function seesaw_register_write_u8`, `function seesaw_register_write_u32`, `function seesaw_read_data`, `function seesaw_open`, `function seesaw_poll`, `function for_each_set_bit`, `function seesaw_probe`.
- 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.