drivers/input/touchscreen/ar1021_i2c.c
Source file repositories/reference/linux-study-clean/drivers/input/touchscreen/ar1021_i2c.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/touchscreen/ar1021_i2c.c- Extension
.c- Size
- 4368 bytes
- Lines
- 193
- 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/bitops.hlinux/module.hlinux/input.hlinux/of.hlinux/i2c.hlinux/irq.hlinux/interrupt.h
Detected Declarations
struct ar1021_i2cfunction ar1021_i2c_irqfunction ar1021_i2c_openfunction ar1021_i2c_closefunction ar1021_i2c_probefunction ar1021_i2c_suspendfunction ar1021_i2c_resume
Annotated Snippet
struct ar1021_i2c {
struct i2c_client *client;
struct input_dev *input;
u8 data[AR1021_TOUCH_PKG_SIZE];
};
static irqreturn_t ar1021_i2c_irq(int irq, void *dev_id)
{
struct ar1021_i2c *ar1021 = dev_id;
struct input_dev *input = ar1021->input;
u8 *data = ar1021->data;
unsigned int x, y, button;
int retval;
retval = i2c_master_recv(ar1021->client,
ar1021->data, sizeof(ar1021->data));
if (retval != sizeof(ar1021->data))
goto out;
/* sync bit set ? */
if (!(data[0] & BIT(7)))
goto out;
button = data[0] & BIT(0);
x = ((data[2] & 0x1f) << 7) | (data[1] & 0x7f);
y = ((data[4] & 0x1f) << 7) | (data[3] & 0x7f);
input_report_abs(input, ABS_X, x);
input_report_abs(input, ABS_Y, y);
input_report_key(input, BTN_TOUCH, button);
input_sync(input);
out:
return IRQ_HANDLED;
}
static int ar1021_i2c_open(struct input_dev *dev)
{
static const u8 cmd_enable_touch[] = {
AR1021_CMD,
0x01, /* number of bytes after this */
AR1021_CMD_ENABLE_TOUCH
};
struct ar1021_i2c *ar1021 = input_get_drvdata(dev);
struct i2c_client *client = ar1021->client;
int error;
error = i2c_master_send(ar1021->client, cmd_enable_touch,
sizeof(cmd_enable_touch));
if (error < 0)
return error;
enable_irq(client->irq);
return 0;
}
static void ar1021_i2c_close(struct input_dev *dev)
{
struct ar1021_i2c *ar1021 = input_get_drvdata(dev);
struct i2c_client *client = ar1021->client;
disable_irq(client->irq);
}
static int ar1021_i2c_probe(struct i2c_client *client)
{
struct ar1021_i2c *ar1021;
struct input_dev *input;
int error;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
dev_err(&client->dev, "i2c_check_functionality error\n");
return -ENXIO;
}
ar1021 = devm_kzalloc(&client->dev, sizeof(*ar1021), GFP_KERNEL);
if (!ar1021)
return -ENOMEM;
input = devm_input_allocate_device(&client->dev);
if (!input)
return -ENOMEM;
ar1021->client = client;
ar1021->input = input;
input->name = "ar1021 I2C Touchscreen";
input->id.bustype = BUS_I2C;
input->dev.parent = &client->dev;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/module.h`, `linux/input.h`, `linux/of.h`, `linux/i2c.h`, `linux/irq.h`, `linux/interrupt.h`.
- Detected declarations: `struct ar1021_i2c`, `function ar1021_i2c_irq`, `function ar1021_i2c_open`, `function ar1021_i2c_close`, `function ar1021_i2c_probe`, `function ar1021_i2c_suspend`, `function ar1021_i2c_resume`.
- 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.