Lines Matching +full:max77693 +full:- +full:haptic

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MAXIM MAX77693/MAX77843 Haptic device driver
24 #include <linux/mfd/max77693.h>
25 #include <linux/mfd/max77693-common.h>
26 #include <linux/mfd/max77693-private.h>
27 #include <linux/mfd/max77705-private.h>
28 #include <linux/mfd/max77843-private.h>
69 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic) in max77693_haptic_set_duty_cycle() argument
74 pwm_init_state(haptic->pwm_dev, &state); in max77693_haptic_set_duty_cycle()
75 state.duty_cycle = (state.period + haptic->pwm_duty) / 2; in max77693_haptic_set_duty_cycle()
77 error = pwm_apply_might_sleep(haptic->pwm_dev, &state); in max77693_haptic_set_duty_cycle()
79 dev_err(haptic->dev, in max77693_haptic_set_duty_cycle()
87 static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on) in max77843_haptic_bias() argument
91 if (haptic->dev_type != TYPE_MAX77843) in max77843_haptic_bias()
94 error = regmap_update_bits(haptic->regmap_haptic, in max77843_haptic_bias()
99 dev_err(haptic->dev, "failed to %s bias: %d\n", in max77843_haptic_bias()
107 static int max77693_haptic_configure(struct max77693_haptic *haptic, in max77693_haptic_configure() argument
113 switch (haptic->dev_type) { in max77693_haptic_configure()
115 value = ((haptic->type << MAX77693_CONFIG2_MODE) | in max77693_haptic_configure()
117 (haptic->mode << MAX77693_CONFIG2_HTYP) | in max77693_haptic_configure()
122 value = ((haptic->type << MAX77693_CONFIG2_MODE) | in max77693_haptic_configure()
124 (haptic->mode << MAX77693_CONFIG2_HTYP) | in max77693_haptic_configure()
129 value = (haptic->type << MCONFIG_MODE_SHIFT) | in max77693_haptic_configure()
135 return -EINVAL; in max77693_haptic_configure()
138 error = regmap_write(haptic->regmap_haptic, in max77693_haptic_configure()
141 dev_err(haptic->dev, in max77693_haptic_configure()
142 "failed to update haptic config: %d\n", error); in max77693_haptic_configure()
149 static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable) in max77693_haptic_lowsys() argument
153 if (haptic->dev_type != TYPE_MAX77693) in max77693_haptic_lowsys()
156 error = regmap_update_bits(haptic->regmap_pmic, in max77693_haptic_lowsys()
161 dev_err(haptic->dev, "cannot update pmic regmap: %d\n", error); in max77693_haptic_lowsys()
168 static void max77693_haptic_enable(struct max77693_haptic *haptic) in max77693_haptic_enable() argument
173 if (haptic->enabled) in max77693_haptic_enable()
176 pwm_init_state(haptic->pwm_dev, &state); in max77693_haptic_enable()
177 state.duty_cycle = (state.period + haptic->pwm_duty) / 2; in max77693_haptic_enable()
180 error = pwm_apply_might_sleep(haptic->pwm_dev, &state); in max77693_haptic_enable()
182 dev_err(haptic->dev, in max77693_haptic_enable()
183 "failed to enable haptic pwm device: %d\n", error); in max77693_haptic_enable()
187 error = max77693_haptic_lowsys(haptic, true); in max77693_haptic_enable()
191 error = max77693_haptic_configure(haptic, true); in max77693_haptic_enable()
195 haptic->enabled = true; in max77693_haptic_enable()
200 max77693_haptic_lowsys(haptic, false); in max77693_haptic_enable()
202 pwm_disable(haptic->pwm_dev); in max77693_haptic_enable()
205 static void max77693_haptic_disable(struct max77693_haptic *haptic) in max77693_haptic_disable() argument
209 if (!haptic->enabled) in max77693_haptic_disable()
212 error = max77693_haptic_configure(haptic, false); in max77693_haptic_disable()
216 error = max77693_haptic_lowsys(haptic, false); in max77693_haptic_disable()
220 pwm_disable(haptic->pwm_dev); in max77693_haptic_disable()
221 haptic->enabled = false; in max77693_haptic_disable()
226 max77693_haptic_configure(haptic, true); in max77693_haptic_disable()
231 struct max77693_haptic *haptic = in max77693_haptic_play_work() local
234 if (!haptic->magnitude) in max77693_haptic_play_work()
235 max77693_haptic_disable(haptic); in max77693_haptic_play_work()
236 else if (haptic->enabled) in max77693_haptic_play_work()
237 max77693_haptic_set_duty_cycle(haptic); in max77693_haptic_play_work()
239 max77693_haptic_enable(haptic); in max77693_haptic_play_work()
245 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_play_effect() local
249 haptic->magnitude = effect->u.rumble.strong_magnitude; in max77693_haptic_play_effect()
250 if (!haptic->magnitude) in max77693_haptic_play_effect()
251 haptic->magnitude = effect->u.rumble.weak_magnitude; in max77693_haptic_play_effect()
254 * The magnitude comes from force-feedback interface. in max77693_haptic_play_effect()
256 * - pwm_duty = (magnitude * pwm_period) / MAX_MAGNITUDE(0xFFFF) in max77693_haptic_play_effect()
258 pwm_get_args(haptic->pwm_dev, &pargs); in max77693_haptic_play_effect()
259 period_mag_multi = (u64)pargs.period * haptic->magnitude; in max77693_haptic_play_effect()
260 haptic->pwm_duty = (unsigned int)(period_mag_multi >> in max77693_haptic_play_effect()
263 schedule_work(&haptic->work); in max77693_haptic_play_effect()
270 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_open() local
273 error = max77843_haptic_bias(haptic, true); in max77693_haptic_open()
277 error = regulator_enable(haptic->motor_reg); in max77693_haptic_open()
279 dev_err(haptic->dev, in max77693_haptic_open()
289 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_close() local
292 cancel_work_sync(&haptic->work); in max77693_haptic_close()
293 max77693_haptic_disable(haptic); in max77693_haptic_close()
295 error = regulator_disable(haptic->motor_reg); in max77693_haptic_close()
297 dev_err(haptic->dev, in max77693_haptic_close()
300 max77843_haptic_bias(haptic, false); in max77693_haptic_close()
305 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent); in max77693_haptic_probe() local
306 struct max77693_haptic *haptic; in max77693_haptic_probe() local
309 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in max77693_haptic_probe()
310 if (!haptic) in max77693_haptic_probe()
311 return -ENOMEM; in max77693_haptic_probe()
313 haptic->regmap_pmic = max77693->regmap; in max77693_haptic_probe()
314 haptic->dev = &pdev->dev; in max77693_haptic_probe()
315 haptic->type = MAX77693_HAPTIC_LRA; in max77693_haptic_probe()
316 haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; in max77693_haptic_probe()
317 haptic->suspend_state = false; in max77693_haptic_probe()
319 /* Variant-specific init */ in max77693_haptic_probe()
320 haptic->dev_type = max77693->type; in max77693_haptic_probe()
321 switch (haptic->dev_type) { in max77693_haptic_probe()
323 haptic->regmap_haptic = max77693->regmap_haptic; in max77693_haptic_probe()
327 haptic->regmap_haptic = max77693->regmap; in max77693_haptic_probe()
330 dev_err(&pdev->dev, "unsupported device type: %u\n", in max77693_haptic_probe()
331 haptic->dev_type); in max77693_haptic_probe()
332 return -EINVAL; in max77693_haptic_probe()
335 INIT_WORK(&haptic->work, max77693_haptic_play_work); in max77693_haptic_probe()
337 /* Get pwm and regulatot for haptic device */ in max77693_haptic_probe()
338 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); in max77693_haptic_probe()
339 if (IS_ERR(haptic->pwm_dev)) { in max77693_haptic_probe()
340 dev_err(&pdev->dev, "failed to get pwm device\n"); in max77693_haptic_probe()
341 return PTR_ERR(haptic->pwm_dev); in max77693_haptic_probe()
344 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic"); in max77693_haptic_probe()
345 if (IS_ERR(haptic->motor_reg)) { in max77693_haptic_probe()
346 dev_err(&pdev->dev, "failed to get regulator\n"); in max77693_haptic_probe()
347 return PTR_ERR(haptic->motor_reg); in max77693_haptic_probe()
350 /* Initialize input device for haptic device */ in max77693_haptic_probe()
351 haptic->input_dev = devm_input_allocate_device(&pdev->dev); in max77693_haptic_probe()
352 if (!haptic->input_dev) { in max77693_haptic_probe()
353 dev_err(&pdev->dev, "failed to allocate input device\n"); in max77693_haptic_probe()
354 return -ENOMEM; in max77693_haptic_probe()
357 haptic->input_dev->name = "max77693-haptic"; in max77693_haptic_probe()
358 haptic->input_dev->id.version = 1; in max77693_haptic_probe()
359 haptic->input_dev->dev.parent = &pdev->dev; in max77693_haptic_probe()
360 haptic->input_dev->open = max77693_haptic_open; in max77693_haptic_probe()
361 haptic->input_dev->close = max77693_haptic_close; in max77693_haptic_probe()
362 input_set_drvdata(haptic->input_dev, haptic); in max77693_haptic_probe()
363 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in max77693_haptic_probe()
365 error = input_ff_create_memless(haptic->input_dev, NULL, in max77693_haptic_probe()
368 dev_err(&pdev->dev, "failed to create force-feedback\n"); in max77693_haptic_probe()
372 error = input_register_device(haptic->input_dev); in max77693_haptic_probe()
374 dev_err(&pdev->dev, "failed to register input device\n"); in max77693_haptic_probe()
378 platform_set_drvdata(pdev, haptic); in max77693_haptic_probe()
386 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_suspend() local
388 if (haptic->enabled) { in max77693_haptic_suspend()
389 max77693_haptic_disable(haptic); in max77693_haptic_suspend()
390 haptic->suspend_state = true; in max77693_haptic_suspend()
399 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_resume() local
401 if (haptic->suspend_state) { in max77693_haptic_resume()
402 max77693_haptic_enable(haptic); in max77693_haptic_resume()
403 haptic->suspend_state = false; in max77693_haptic_resume()
414 { "max77693-haptic", },
415 { "max77705-haptic", },
416 { "max77843-haptic", },
422 { .compatible = "maxim,max77693-haptic", },
423 { .compatible = "maxim,max77705-haptic", },
424 { .compatible = "maxim,max77843-haptic", },
431 .name = "max77693-haptic",
442 MODULE_DESCRIPTION("MAXIM 77693/77705/77843 Haptic driver");