drivers/input/joystick/as5011.c
Source file repositories/reference/linux-study-clean/drivers/input/joystick/as5011.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/joystick/as5011.c- Extension
.c- Size
- 8570 bytes
- Lines
- 355
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/i2c.hlinux/interrupt.hlinux/input.hlinux/gpio/consumer.hlinux/delay.hlinux/input/as5011.hlinux/slab.hlinux/module.h
Detected Declarations
struct as5011_devicefunction as5011_i2c_writefunction as5011_i2c_readfunction as5011_button_interruptfunction as5011_axis_interruptfunction as5011_configure_chipfunction as5011_probefunction as5011_remove
Annotated Snippet
struct as5011_device {
struct input_dev *input_dev;
struct i2c_client *i2c_client;
struct gpio_desc *button_gpiod;
unsigned int button_irq;
unsigned int axis_irq;
};
static int as5011_i2c_write(struct i2c_client *client,
uint8_t aregaddr,
uint8_t avalue)
{
uint8_t data[2] = { aregaddr, avalue };
struct i2c_msg msg = {
.addr = client->addr,
.flags = I2C_M_IGNORE_NAK,
.len = 2,
.buf = (uint8_t *)data
};
int error;
error = i2c_transfer(client->adapter, &msg, 1);
return error < 0 ? error : 0;
}
static int as5011_i2c_read(struct i2c_client *client,
uint8_t aregaddr, signed char *value)
{
uint8_t data[2] = { aregaddr };
struct i2c_msg msg_set[2] = {
{
.addr = client->addr,
.flags = I2C_M_REV_DIR_ADDR,
.len = 1,
.buf = (uint8_t *)data
},
{
.addr = client->addr,
.flags = I2C_M_RD | I2C_M_NOSTART,
.len = 1,
.buf = (uint8_t *)data
}
};
int error;
error = i2c_transfer(client->adapter, msg_set, 2);
if (error < 0)
return error;
*value = data[0] & 0x80 ? -1 * (1 + ~data[0]) : data[0];
return 0;
}
static irqreturn_t as5011_button_interrupt(int irq, void *dev_id)
{
struct as5011_device *as5011 = dev_id;
int val = gpiod_get_value_cansleep(as5011->button_gpiod);
input_report_key(as5011->input_dev, BTN_JOYSTICK, !val);
input_sync(as5011->input_dev);
return IRQ_HANDLED;
}
static irqreturn_t as5011_axis_interrupt(int irq, void *dev_id)
{
struct as5011_device *as5011 = dev_id;
int error;
signed char x, y;
error = as5011_i2c_read(as5011->i2c_client, AS5011_X_RES_INT, &x);
if (error < 0)
goto out;
error = as5011_i2c_read(as5011->i2c_client, AS5011_Y_RES_INT, &y);
if (error < 0)
goto out;
input_report_abs(as5011->input_dev, ABS_X, x);
input_report_abs(as5011->input_dev, ABS_Y, y);
input_sync(as5011->input_dev);
out:
return IRQ_HANDLED;
}
static int as5011_configure_chip(struct as5011_device *as5011,
const struct as5011_platform_data *plat_dat)
{
struct i2c_client *client = as5011->i2c_client;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/interrupt.h`, `linux/input.h`, `linux/gpio/consumer.h`, `linux/delay.h`, `linux/input/as5011.h`, `linux/slab.h`, `linux/module.h`.
- Detected declarations: `struct as5011_device`, `function as5011_i2c_write`, `function as5011_i2c_read`, `function as5011_button_interrupt`, `function as5011_axis_interrupt`, `function as5011_configure_chip`, `function as5011_probe`, `function as5011_remove`.
- Atlas domain: Driver Families / drivers/input.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.