drivers/input/mouse/gpio_mouse.c
Source file repositories/reference/linux-study-clean/drivers/input/mouse/gpio_mouse.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/mouse/gpio_mouse.c- Extension
.c- Size
- 4736 bytes
- Lines
- 171
- 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/module.hlinux/platform_device.hlinux/input.hlinux/gpio/consumer.hlinux/property.hlinux/of.h
Detected Declarations
struct gpio_mousefunction gpio_mouse_scanfunction gpio_mouse_probe
Annotated Snippet
struct gpio_mouse {
u32 scan_ms;
struct gpio_desc *up;
struct gpio_desc *down;
struct gpio_desc *left;
struct gpio_desc *right;
struct gpio_desc *bleft;
struct gpio_desc *bmiddle;
struct gpio_desc *bright;
};
/*
* Timer function which is run every scan_ms ms when the device is opened.
* The dev input variable is set to the input_dev pointer.
*/
static void gpio_mouse_scan(struct input_dev *input)
{
struct gpio_mouse *gpio = input_get_drvdata(input);
int x, y;
if (gpio->bleft)
input_report_key(input, BTN_LEFT,
gpiod_get_value(gpio->bleft));
if (gpio->bmiddle)
input_report_key(input, BTN_MIDDLE,
gpiod_get_value(gpio->bmiddle));
if (gpio->bright)
input_report_key(input, BTN_RIGHT,
gpiod_get_value(gpio->bright));
x = gpiod_get_value(gpio->right) - gpiod_get_value(gpio->left);
y = gpiod_get_value(gpio->down) - gpiod_get_value(gpio->up);
input_report_rel(input, REL_X, x);
input_report_rel(input, REL_Y, y);
input_sync(input);
}
static int gpio_mouse_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct gpio_mouse *gmouse;
struct input_dev *input;
int error;
gmouse = devm_kzalloc(dev, sizeof(*gmouse), GFP_KERNEL);
if (!gmouse)
return -ENOMEM;
/* Assign some default scanning time */
error = device_property_read_u32(dev, "scan-interval-ms",
&gmouse->scan_ms);
if (error || gmouse->scan_ms == 0) {
dev_warn(dev, "invalid scan time, set to 50 ms\n");
gmouse->scan_ms = 50;
}
gmouse->up = devm_gpiod_get(dev, "up", GPIOD_IN);
if (IS_ERR(gmouse->up))
return PTR_ERR(gmouse->up);
gmouse->down = devm_gpiod_get(dev, "down", GPIOD_IN);
if (IS_ERR(gmouse->down))
return PTR_ERR(gmouse->down);
gmouse->left = devm_gpiod_get(dev, "left", GPIOD_IN);
if (IS_ERR(gmouse->left))
return PTR_ERR(gmouse->left);
gmouse->right = devm_gpiod_get(dev, "right", GPIOD_IN);
if (IS_ERR(gmouse->right))
return PTR_ERR(gmouse->right);
gmouse->bleft = devm_gpiod_get_optional(dev, "button-left", GPIOD_IN);
if (IS_ERR(gmouse->bleft))
return PTR_ERR(gmouse->bleft);
gmouse->bmiddle = devm_gpiod_get_optional(dev, "button-middle",
GPIOD_IN);
if (IS_ERR(gmouse->bmiddle))
return PTR_ERR(gmouse->bmiddle);
gmouse->bright = devm_gpiod_get_optional(dev, "button-right",
GPIOD_IN);
if (IS_ERR(gmouse->bright))
return PTR_ERR(gmouse->bright);
input = devm_input_allocate_device(dev);
if (!input)
return -ENOMEM;
input->name = pdev->name;
input->id.bustype = BUS_HOST;
input_set_drvdata(input, gmouse);
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/input.h`, `linux/gpio/consumer.h`, `linux/property.h`, `linux/of.h`.
- Detected declarations: `struct gpio_mouse`, `function gpio_mouse_scan`, `function gpio_mouse_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.