Lines Matching refs:haptic

59 static int max77843_haptic_set_duty_cycle(struct max77843_haptic *haptic)  in max77843_haptic_set_duty_cycle()  argument
61 int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; in max77843_haptic_set_duty_cycle()
64 error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); in max77843_haptic_set_duty_cycle()
66 dev_err(haptic->dev, "failed to configure pwm: %d\n", error); in max77843_haptic_set_duty_cycle()
73 static int max77843_haptic_bias(struct max77843_haptic *haptic, bool on) in max77843_haptic_bias() argument
77 error = regmap_update_bits(haptic->regmap_haptic, in max77843_haptic_bias()
82 dev_err(haptic->dev, "failed to %s bias: %d\n", in max77843_haptic_bias()
90 static int max77843_haptic_config(struct max77843_haptic *haptic, bool enable) in max77843_haptic_config() argument
95 value = (haptic->type << MCONFIG_MODE_SHIFT) | in max77843_haptic_config()
97 (haptic->pwm_divisor << MCONFIG_PDIV_SHIFT); in max77843_haptic_config()
99 error = regmap_write(haptic->regmap_haptic, in max77843_haptic_config()
102 dev_err(haptic->dev, in max77843_haptic_config()
110 static int max77843_haptic_enable(struct max77843_haptic *haptic) in max77843_haptic_enable() argument
114 if (haptic->active) in max77843_haptic_enable()
117 error = pwm_enable(haptic->pwm_dev); in max77843_haptic_enable()
119 dev_err(haptic->dev, in max77843_haptic_enable()
124 error = max77843_haptic_config(haptic, true); in max77843_haptic_enable()
128 haptic->active = true; in max77843_haptic_enable()
133 pwm_disable(haptic->pwm_dev); in max77843_haptic_enable()
138 static int max77843_haptic_disable(struct max77843_haptic *haptic) in max77843_haptic_disable() argument
142 if (!haptic->active) in max77843_haptic_disable()
145 error = max77843_haptic_config(haptic, false); in max77843_haptic_disable()
149 pwm_disable(haptic->pwm_dev); in max77843_haptic_disable()
151 haptic->active = false; in max77843_haptic_disable()
158 struct max77843_haptic *haptic = in max77843_haptic_play_work() local
162 mutex_lock(&haptic->mutex); in max77843_haptic_play_work()
164 if (haptic->suspended) in max77843_haptic_play_work()
167 if (haptic->magnitude) { in max77843_haptic_play_work()
168 error = max77843_haptic_set_duty_cycle(haptic); in max77843_haptic_play_work()
170 dev_err(haptic->dev, in max77843_haptic_play_work()
175 error = max77843_haptic_enable(haptic); in max77843_haptic_play_work()
177 dev_err(haptic->dev, in max77843_haptic_play_work()
180 error = max77843_haptic_disable(haptic); in max77843_haptic_play_work()
182 dev_err(haptic->dev, in max77843_haptic_play_work()
187 mutex_unlock(&haptic->mutex); in max77843_haptic_play_work()
193 struct max77843_haptic *haptic = input_get_drvdata(dev); in max77843_haptic_play_effect() local
196 haptic->magnitude = effect->u.rumble.strong_magnitude; in max77843_haptic_play_effect()
197 if (!haptic->magnitude) in max77843_haptic_play_effect()
198 haptic->magnitude = effect->u.rumble.weak_magnitude; in max77843_haptic_play_effect()
200 period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude; in max77843_haptic_play_effect()
201 haptic->pwm_duty = (unsigned int)(period_mag_multi >> in max77843_haptic_play_effect()
204 schedule_work(&haptic->work); in max77843_haptic_play_effect()
211 struct max77843_haptic *haptic = input_get_drvdata(dev); in max77843_haptic_open() local
214 error = max77843_haptic_bias(haptic, true); in max77843_haptic_open()
218 error = regulator_enable(haptic->motor_reg); in max77843_haptic_open()
220 dev_err(haptic->dev, in max77843_haptic_open()
230 struct max77843_haptic *haptic = input_get_drvdata(dev); in max77843_haptic_close() local
233 cancel_work_sync(&haptic->work); in max77843_haptic_close()
234 max77843_haptic_disable(haptic); in max77843_haptic_close()
236 error = regulator_disable(haptic->motor_reg); in max77843_haptic_close()
238 dev_err(haptic->dev, in max77843_haptic_close()
241 max77843_haptic_bias(haptic, false); in max77843_haptic_close()
247 struct max77843_haptic *haptic; in max77843_haptic_probe() local
250 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in max77843_haptic_probe()
251 if (!haptic) in max77843_haptic_probe()
254 haptic->regmap_haptic = max77843->regmap; in max77843_haptic_probe()
255 haptic->dev = &pdev->dev; in max77843_haptic_probe()
256 haptic->type = MAX77843_HAPTIC_LRA; in max77843_haptic_probe()
257 haptic->pwm_divisor = MAX77843_HAPTIC_PWM_DIVISOR_128; in max77843_haptic_probe()
259 INIT_WORK(&haptic->work, max77843_haptic_play_work); in max77843_haptic_probe()
260 mutex_init(&haptic->mutex); in max77843_haptic_probe()
262 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); in max77843_haptic_probe()
263 if (IS_ERR(haptic->pwm_dev)) { in max77843_haptic_probe()
265 return PTR_ERR(haptic->pwm_dev); in max77843_haptic_probe()
268 haptic->motor_reg = devm_regulator_get_exclusive(&pdev->dev, "haptic"); in max77843_haptic_probe()
269 if (IS_ERR(haptic->motor_reg)) { in max77843_haptic_probe()
271 return PTR_ERR(haptic->motor_reg); in max77843_haptic_probe()
274 haptic->input_dev = devm_input_allocate_device(&pdev->dev); in max77843_haptic_probe()
275 if (!haptic->input_dev) { in max77843_haptic_probe()
280 haptic->input_dev->name = "max77843-haptic"; in max77843_haptic_probe()
281 haptic->input_dev->id.version = 1; in max77843_haptic_probe()
282 haptic->input_dev->dev.parent = &pdev->dev; in max77843_haptic_probe()
283 haptic->input_dev->open = max77843_haptic_open; in max77843_haptic_probe()
284 haptic->input_dev->close = max77843_haptic_close; in max77843_haptic_probe()
285 input_set_drvdata(haptic->input_dev, haptic); in max77843_haptic_probe()
286 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in max77843_haptic_probe()
288 error = input_ff_create_memless(haptic->input_dev, NULL, in max77843_haptic_probe()
295 error = input_register_device(haptic->input_dev); in max77843_haptic_probe()
301 platform_set_drvdata(pdev, haptic); in max77843_haptic_probe()
309 struct max77843_haptic *haptic = platform_get_drvdata(pdev); in max77843_haptic_suspend() local
312 error = mutex_lock_interruptible(&haptic->mutex); in max77843_haptic_suspend()
316 max77843_haptic_disable(haptic); in max77843_haptic_suspend()
318 haptic->suspended = true; in max77843_haptic_suspend()
320 mutex_unlock(&haptic->mutex); in max77843_haptic_suspend()
328 struct max77843_haptic *haptic = platform_get_drvdata(pdev); in max77843_haptic_resume() local
331 mutex_lock(&haptic->mutex); in max77843_haptic_resume()
333 haptic->suspended = false; in max77843_haptic_resume()
335 magnitude = ACCESS_ONCE(haptic->magnitude); in max77843_haptic_resume()
337 max77843_haptic_enable(haptic); in max77843_haptic_resume()
339 mutex_unlock(&haptic->mutex); in max77843_haptic_resume()