drivers/input/misc/gpio-vibra.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/gpio-vibra.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/gpio-vibra.c- Extension
.c- Size
- 4880 bytes
- Lines
- 200
- 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/gpio/consumer.hlinux/input.hlinux/kernel.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/property.hlinux/regulator/consumer.hlinux/slab.h
Detected Declarations
struct gpio_vibratorfunction gpio_vibrator_startfunction gpio_vibrator_stopfunction gpio_vibrator_play_workfunction gpio_vibrator_play_effectfunction gpio_vibrator_closefunction gpio_vibrator_probefunction gpio_vibrator_suspendfunction gpio_vibrator_resume
Annotated Snippet
struct gpio_vibrator {
struct input_dev *input;
struct gpio_desc *gpio;
struct regulator *vcc;
struct work_struct play_work;
bool running;
bool vcc_on;
};
static int gpio_vibrator_start(struct gpio_vibrator *vibrator)
{
struct device *pdev = vibrator->input->dev.parent;
int err;
if (!vibrator->vcc_on) {
err = regulator_enable(vibrator->vcc);
if (err) {
dev_err(pdev, "failed to enable regulator: %d\n", err);
return err;
}
vibrator->vcc_on = true;
}
gpiod_set_value_cansleep(vibrator->gpio, 1);
return 0;
}
static void gpio_vibrator_stop(struct gpio_vibrator *vibrator)
{
gpiod_set_value_cansleep(vibrator->gpio, 0);
if (vibrator->vcc_on) {
regulator_disable(vibrator->vcc);
vibrator->vcc_on = false;
}
}
static void gpio_vibrator_play_work(struct work_struct *work)
{
struct gpio_vibrator *vibrator =
container_of(work, struct gpio_vibrator, play_work);
if (vibrator->running)
gpio_vibrator_start(vibrator);
else
gpio_vibrator_stop(vibrator);
}
static int gpio_vibrator_play_effect(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct gpio_vibrator *vibrator = input_get_drvdata(dev);
int level;
level = effect->u.rumble.strong_magnitude;
if (!level)
level = effect->u.rumble.weak_magnitude;
vibrator->running = level;
schedule_work(&vibrator->play_work);
return 0;
}
static void gpio_vibrator_close(struct input_dev *input)
{
struct gpio_vibrator *vibrator = input_get_drvdata(input);
cancel_work_sync(&vibrator->play_work);
gpio_vibrator_stop(vibrator);
vibrator->running = false;
}
static int gpio_vibrator_probe(struct platform_device *pdev)
{
struct gpio_vibrator *vibrator;
int err;
vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL);
if (!vibrator)
return -ENOMEM;
vibrator->input = devm_input_allocate_device(&pdev->dev);
if (!vibrator->input)
return -ENOMEM;
vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc");
if (IS_ERR(vibrator->vcc))
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/input.h`, `linux/kernel.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/property.h`, `linux/regulator/consumer.h`.
- Detected declarations: `struct gpio_vibrator`, `function gpio_vibrator_start`, `function gpio_vibrator_stop`, `function gpio_vibrator_play_work`, `function gpio_vibrator_play_effect`, `function gpio_vibrator_close`, `function gpio_vibrator_probe`, `function gpio_vibrator_suspend`, `function gpio_vibrator_resume`.
- 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.