Lines Matching +full:gpio +full:- +full:beeper

1 // SPDX-License-Identifier: GPL-2.0+
3 * GPIO vibrator driver
13 * Based on PWM beeper driver:
14 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
17 #include <linux/gpio/consumer.h>
29 struct gpio_desc *gpio; member
39 struct device *pdev = vibrator->input->dev.parent; in gpio_vibrator_start()
42 if (!vibrator->vcc_on) { in gpio_vibrator_start()
43 err = regulator_enable(vibrator->vcc); in gpio_vibrator_start()
48 vibrator->vcc_on = true; in gpio_vibrator_start()
51 gpiod_set_value_cansleep(vibrator->gpio, 1); in gpio_vibrator_start()
58 gpiod_set_value_cansleep(vibrator->gpio, 0); in gpio_vibrator_stop()
60 if (vibrator->vcc_on) { in gpio_vibrator_stop()
61 regulator_disable(vibrator->vcc); in gpio_vibrator_stop()
62 vibrator->vcc_on = false; in gpio_vibrator_stop()
71 if (vibrator->running) in gpio_vibrator_play_work()
83 level = effect->u.rumble.strong_magnitude; in gpio_vibrator_play_effect()
85 level = effect->u.rumble.weak_magnitude; in gpio_vibrator_play_effect()
87 vibrator->running = level; in gpio_vibrator_play_effect()
88 schedule_work(&vibrator->play_work); in gpio_vibrator_play_effect()
97 cancel_work_sync(&vibrator->play_work); in gpio_vibrator_close()
99 vibrator->running = false; in gpio_vibrator_close()
107 vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL); in gpio_vibrator_probe()
109 return -ENOMEM; in gpio_vibrator_probe()
111 vibrator->input = devm_input_allocate_device(&pdev->dev); in gpio_vibrator_probe()
112 if (!vibrator->input) in gpio_vibrator_probe()
113 return -ENOMEM; in gpio_vibrator_probe()
115 vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc"); in gpio_vibrator_probe()
116 if (IS_ERR(vibrator->vcc)) in gpio_vibrator_probe()
117 return dev_err_probe(&pdev->dev, PTR_ERR(vibrator->vcc), in gpio_vibrator_probe()
120 vibrator->gpio = devm_gpiod_get(&pdev->dev, "enable", GPIOD_OUT_LOW); in gpio_vibrator_probe()
121 if (IS_ERR(vibrator->gpio)) in gpio_vibrator_probe()
122 return dev_err_probe(&pdev->dev, PTR_ERR(vibrator->gpio), in gpio_vibrator_probe()
123 "Failed to request main gpio\n"); in gpio_vibrator_probe()
125 INIT_WORK(&vibrator->play_work, gpio_vibrator_play_work); in gpio_vibrator_probe()
127 vibrator->input->name = "gpio-vibrator"; in gpio_vibrator_probe()
128 vibrator->input->id.bustype = BUS_HOST; in gpio_vibrator_probe()
129 vibrator->input->close = gpio_vibrator_close; in gpio_vibrator_probe()
131 input_set_drvdata(vibrator->input, vibrator); in gpio_vibrator_probe()
132 input_set_capability(vibrator->input, EV_FF, FF_RUMBLE); in gpio_vibrator_probe()
134 err = input_ff_create_memless(vibrator->input, NULL, in gpio_vibrator_probe()
137 dev_err(&pdev->dev, "Couldn't create FF dev: %d\n", err); in gpio_vibrator_probe()
141 err = input_register_device(vibrator->input); in gpio_vibrator_probe()
143 dev_err(&pdev->dev, "Couldn't register input dev: %d\n", err); in gpio_vibrator_probe()
157 cancel_work_sync(&vibrator->play_work); in gpio_vibrator_suspend()
158 if (vibrator->running) in gpio_vibrator_suspend()
169 if (vibrator->running) in gpio_vibrator_resume()
180 { .compatible = "gpio-vibrator" },
189 .name = "gpio-vibrator",
197 MODULE_DESCRIPTION("GPIO vibrator driver");
199 MODULE_ALIAS("platform:gpio-vibrator");