drivers/input/misc/pwm-vibra.c
Source file repositories/reference/linux-study-clean/drivers/input/misc/pwm-vibra.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/input/misc/pwm-vibra.c- Extension
.c- Size
- 6821 bytes
- Lines
- 275
- 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/pwm.hlinux/regulator/consumer.hlinux/slab.h
Detected Declarations
struct pwm_vibratorfunction pwm_vibrator_startfunction pwm_vibrator_stopfunction pwm_vibrator_play_workfunction pwm_vibrator_play_effectfunction pwm_vibrator_closefunction pwm_vibrator_probefunction pwm_vibrator_suspendfunction pwm_vibrator_resume
Annotated Snippet
struct pwm_vibrator {
struct input_dev *input;
struct gpio_desc *enable_gpio;
struct pwm_device *pwm;
struct pwm_device *pwm_dir;
struct regulator *vcc;
struct work_struct play_work;
u16 level;
u32 direction_duty_cycle;
bool vcc_on;
};
static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
{
struct device *pdev = vibrator->input->dev.parent;
struct pwm_state state;
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->enable_gpio, 1);
pwm_get_state(vibrator->pwm, &state);
pwm_set_relative_duty_cycle(&state, vibrator->level, 0xffff);
state.enabled = true;
err = pwm_apply_might_sleep(vibrator->pwm, &state);
if (err) {
dev_err(pdev, "failed to apply pwm state: %d\n", err);
return err;
}
if (vibrator->pwm_dir) {
pwm_get_state(vibrator->pwm_dir, &state);
state.duty_cycle = vibrator->direction_duty_cycle;
state.enabled = true;
err = pwm_apply_might_sleep(vibrator->pwm_dir, &state);
if (err) {
dev_err(pdev, "failed to apply dir-pwm state: %d\n", err);
pwm_disable(vibrator->pwm);
return err;
}
}
return 0;
}
static void pwm_vibrator_stop(struct pwm_vibrator *vibrator)
{
if (vibrator->pwm_dir)
pwm_disable(vibrator->pwm_dir);
pwm_disable(vibrator->pwm);
gpiod_set_value_cansleep(vibrator->enable_gpio, 0);
if (vibrator->vcc_on) {
regulator_disable(vibrator->vcc);
vibrator->vcc_on = false;
}
}
static void pwm_vibrator_play_work(struct work_struct *work)
{
struct pwm_vibrator *vibrator = container_of(work,
struct pwm_vibrator, play_work);
if (vibrator->level)
pwm_vibrator_start(vibrator);
else
pwm_vibrator_stop(vibrator);
}
static int pwm_vibrator_play_effect(struct input_dev *dev, void *data,
struct ff_effect *effect)
{
struct pwm_vibrator *vibrator = input_get_drvdata(dev);
vibrator->level = effect->u.rumble.strong_magnitude;
if (!vibrator->level)
vibrator->level = effect->u.rumble.weak_magnitude;
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/pwm.h`.
- Detected declarations: `struct pwm_vibrator`, `function pwm_vibrator_start`, `function pwm_vibrator_stop`, `function pwm_vibrator_play_work`, `function pwm_vibrator_play_effect`, `function pwm_vibrator_close`, `function pwm_vibrator_probe`, `function pwm_vibrator_suspend`, `function pwm_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.