Lines Matching +full:direction +full:- +full:duty +full:- +full:cycle +full:- +full:ns

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
40 struct device *pdev = vibrator->input->dev.parent; in pwm_vibrator_start()
44 if (!vibrator->vcc_on) { in pwm_vibrator_start()
45 err = regulator_enable(vibrator->vcc); in pwm_vibrator_start()
50 vibrator->vcc_on = true; in pwm_vibrator_start()
53 gpiod_set_value_cansleep(vibrator->enable_gpio, 1); in pwm_vibrator_start()
55 pwm_get_state(vibrator->pwm, &state); in pwm_vibrator_start()
56 pwm_set_relative_duty_cycle(&state, vibrator->level, 0xffff); in pwm_vibrator_start()
59 err = pwm_apply_might_sleep(vibrator->pwm, &state); in pwm_vibrator_start()
65 if (vibrator->pwm_dir) { in pwm_vibrator_start()
66 pwm_get_state(vibrator->pwm_dir, &state); in pwm_vibrator_start()
67 state.duty_cycle = vibrator->direction_duty_cycle; in pwm_vibrator_start()
70 err = pwm_apply_might_sleep(vibrator->pwm_dir, &state); in pwm_vibrator_start()
72 dev_err(pdev, "failed to apply dir-pwm state: %d\n", err); in pwm_vibrator_start()
73 pwm_disable(vibrator->pwm); in pwm_vibrator_start()
83 if (vibrator->pwm_dir) in pwm_vibrator_stop()
84 pwm_disable(vibrator->pwm_dir); in pwm_vibrator_stop()
85 pwm_disable(vibrator->pwm); in pwm_vibrator_stop()
87 gpiod_set_value_cansleep(vibrator->enable_gpio, 0); in pwm_vibrator_stop()
89 if (vibrator->vcc_on) { in pwm_vibrator_stop()
90 regulator_disable(vibrator->vcc); in pwm_vibrator_stop()
91 vibrator->vcc_on = false; in pwm_vibrator_stop()
100 if (vibrator->level) in pwm_vibrator_play_work()
111 vibrator->level = effect->u.rumble.strong_magnitude; in pwm_vibrator_play_effect()
112 if (!vibrator->level) in pwm_vibrator_play_effect()
113 vibrator->level = effect->u.rumble.weak_magnitude; in pwm_vibrator_play_effect()
115 schedule_work(&vibrator->play_work); in pwm_vibrator_play_effect()
124 cancel_work_sync(&vibrator->play_work); in pwm_vibrator_close()
134 vibrator = devm_kzalloc(&pdev->dev, sizeof(*vibrator), GFP_KERNEL); in pwm_vibrator_probe()
136 return -ENOMEM; in pwm_vibrator_probe()
138 vibrator->input = devm_input_allocate_device(&pdev->dev); in pwm_vibrator_probe()
139 if (!vibrator->input) in pwm_vibrator_probe()
140 return -ENOMEM; in pwm_vibrator_probe()
142 vibrator->vcc = devm_regulator_get(&pdev->dev, "vcc"); in pwm_vibrator_probe()
143 if (IS_ERR(vibrator->vcc)) in pwm_vibrator_probe()
144 return dev_err_probe(&pdev->dev, PTR_ERR(vibrator->vcc), in pwm_vibrator_probe()
147 vibrator->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", in pwm_vibrator_probe()
149 if (IS_ERR(vibrator->enable_gpio)) in pwm_vibrator_probe()
150 return dev_err_probe(&pdev->dev, PTR_ERR(vibrator->enable_gpio), in pwm_vibrator_probe()
153 vibrator->pwm = devm_pwm_get(&pdev->dev, "enable"); in pwm_vibrator_probe()
154 if (IS_ERR(vibrator->pwm)) in pwm_vibrator_probe()
155 return dev_err_probe(&pdev->dev, PTR_ERR(vibrator->pwm), in pwm_vibrator_probe()
158 INIT_WORK(&vibrator->play_work, pwm_vibrator_play_work); in pwm_vibrator_probe()
161 pwm_init_state(vibrator->pwm, &state); in pwm_vibrator_probe()
163 err = pwm_apply_might_sleep(vibrator->pwm, &state); in pwm_vibrator_probe()
165 dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n", in pwm_vibrator_probe()
170 vibrator->pwm_dir = devm_pwm_get(&pdev->dev, "direction"); in pwm_vibrator_probe()
171 err = PTR_ERR_OR_ZERO(vibrator->pwm_dir); in pwm_vibrator_probe()
175 pwm_init_state(vibrator->pwm_dir, &state); in pwm_vibrator_probe()
177 err = pwm_apply_might_sleep(vibrator->pwm_dir, &state); in pwm_vibrator_probe()
179 dev_err(&pdev->dev, "failed to apply initial PWM state: %d\n", in pwm_vibrator_probe()
184 vibrator->direction_duty_cycle = in pwm_vibrator_probe()
185 pwm_get_period(vibrator->pwm_dir) / 2; in pwm_vibrator_probe()
186 device_property_read_u32(&pdev->dev, "direction-duty-cycle-ns", in pwm_vibrator_probe()
187 &vibrator->direction_duty_cycle); in pwm_vibrator_probe()
190 case -ENODATA: in pwm_vibrator_probe()
191 /* Direction PWM is optional */ in pwm_vibrator_probe()
192 vibrator->pwm_dir = NULL; in pwm_vibrator_probe()
196 dev_err(&pdev->dev, "Failed to request direction pwm: %d\n", err); in pwm_vibrator_probe()
199 case -EPROBE_DEFER: in pwm_vibrator_probe()
203 vibrator->input->name = "pwm-vibrator"; in pwm_vibrator_probe()
204 vibrator->input->id.bustype = BUS_HOST; in pwm_vibrator_probe()
205 vibrator->input->dev.parent = &pdev->dev; in pwm_vibrator_probe()
206 vibrator->input->close = pwm_vibrator_close; in pwm_vibrator_probe()
208 input_set_drvdata(vibrator->input, vibrator); in pwm_vibrator_probe()
209 input_set_capability(vibrator->input, EV_FF, FF_RUMBLE); in pwm_vibrator_probe()
211 err = input_ff_create_memless(vibrator->input, NULL, in pwm_vibrator_probe()
214 dev_err(&pdev->dev, "Couldn't create FF dev: %d\n", err); in pwm_vibrator_probe()
218 err = input_register_device(vibrator->input); in pwm_vibrator_probe()
220 dev_err(&pdev->dev, "Couldn't register input dev: %d\n", err); in pwm_vibrator_probe()
233 cancel_work_sync(&vibrator->play_work); in pwm_vibrator_suspend()
234 if (vibrator->level) in pwm_vibrator_suspend()
244 if (vibrator->level) in pwm_vibrator_resume()
255 { .compatible = "pwm-vibrator" },
264 .name = "pwm-vibrator",
274 MODULE_ALIAS("platform:pwm-vibrator");