Skip to content

Commit bcf7849

Browse files
z3ntudtor
authored andcommitted
Input: pwm-vibra - add support for enable GPIO
Some pwm vibrators have a dedicated enable GPIO that needs to be set high so that the vibrator works. Add support for that optionally. Signed-off-by: Luca Weiss <luca@z3ntu.xyz> Reviewed-by: Brian Masney <bmasney@redhat.com> Reviewed-by: Sebastian Reichel <sre@kernel.org> Reviewed-by: Caleb Connolly <caleb.connolly@linaro.org> Link: https://lore.kernel.org/r/20230427-hammerhead-vibra-v1-3-e87eeb94da51@z3ntu.xyz Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 29ebf69 commit bcf7849

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

drivers/input/misc/pwm-vibra.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
1212
*/
1313

14+
#include <linux/gpio/consumer.h>
1415
#include <linux/input.h>
1516
#include <linux/kernel.h>
1617
#include <linux/module.h>
@@ -23,6 +24,7 @@
2324

2425
struct pwm_vibrator {
2526
struct input_dev *input;
27+
struct gpio_desc *enable_gpio;
2628
struct pwm_device *pwm;
2729
struct pwm_device *pwm_dir;
2830
struct regulator *vcc;
@@ -48,6 +50,8 @@ static int pwm_vibrator_start(struct pwm_vibrator *vibrator)
4850
vibrator->vcc_on = true;
4951
}
5052

53+
gpiod_set_value_cansleep(vibrator->enable_gpio, 1);
54+
5155
pwm_get_state(vibrator->pwm, &state);
5256
pwm_set_relative_duty_cycle(&state, vibrator->level, 0xffff);
5357
state.enabled = true;
@@ -80,6 +84,8 @@ static void pwm_vibrator_stop(struct pwm_vibrator *vibrator)
8084
pwm_disable(vibrator->pwm_dir);
8185
pwm_disable(vibrator->pwm);
8286

87+
gpiod_set_value_cansleep(vibrator->enable_gpio, 0);
88+
8389
if (vibrator->vcc_on) {
8490
regulator_disable(vibrator->vcc);
8591
vibrator->vcc_on = false;
@@ -142,6 +148,16 @@ static int pwm_vibrator_probe(struct platform_device *pdev)
142148
return err;
143149
}
144150

151+
vibrator->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable",
152+
GPIOD_OUT_LOW);
153+
err = PTR_ERR_OR_ZERO(vibrator->enable_gpio);
154+
if (err) {
155+
if (err != -EPROBE_DEFER)
156+
dev_err(&pdev->dev, "Failed to request enable gpio: %d\n",
157+
err);
158+
return err;
159+
}
160+
145161
vibrator->pwm = devm_pwm_get(&pdev->dev, "enable");
146162
err = PTR_ERR_OR_ZERO(vibrator->pwm);
147163
if (err) {

0 commit comments

Comments
 (0)