Lines Matching refs:haptic

71 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)  in max77693_haptic_set_duty_cycle()  argument
77 pwm_get_args(haptic->pwm_dev, &pargs); in max77693_haptic_set_duty_cycle()
78 delta = (pargs.period + haptic->pwm_duty) / 2; in max77693_haptic_set_duty_cycle()
79 error = pwm_config(haptic->pwm_dev, delta, pargs.period); in max77693_haptic_set_duty_cycle()
81 dev_err(haptic->dev, "failed to configure pwm: %d\n", error); in max77693_haptic_set_duty_cycle()
88 static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on) in max77843_haptic_bias() argument
92 if (haptic->dev_type != TYPE_MAX77843) in max77843_haptic_bias()
95 error = regmap_update_bits(haptic->regmap_haptic, in max77843_haptic_bias()
100 dev_err(haptic->dev, "failed to %s bias: %d\n", in max77843_haptic_bias()
108 static int max77693_haptic_configure(struct max77693_haptic *haptic, in max77693_haptic_configure() argument
114 switch (haptic->dev_type) { in max77693_haptic_configure()
116 value = ((haptic->type << MAX77693_CONFIG2_MODE) | in max77693_haptic_configure()
118 (haptic->mode << MAX77693_CONFIG2_HTYP) | in max77693_haptic_configure()
123 value = (haptic->type << MCONFIG_MODE_SHIFT) | in max77693_haptic_configure()
132 error = regmap_write(haptic->regmap_haptic, in max77693_haptic_configure()
135 dev_err(haptic->dev, in max77693_haptic_configure()
143 static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable) in max77693_haptic_lowsys() argument
147 if (haptic->dev_type != TYPE_MAX77693) in max77693_haptic_lowsys()
150 error = regmap_update_bits(haptic->regmap_pmic, in max77693_haptic_lowsys()
155 dev_err(haptic->dev, "cannot update pmic regmap: %d\n", error); in max77693_haptic_lowsys()
162 static void max77693_haptic_enable(struct max77693_haptic *haptic) in max77693_haptic_enable() argument
166 if (haptic->enabled) in max77693_haptic_enable()
169 error = pwm_enable(haptic->pwm_dev); in max77693_haptic_enable()
171 dev_err(haptic->dev, in max77693_haptic_enable()
176 error = max77693_haptic_lowsys(haptic, true); in max77693_haptic_enable()
180 error = max77693_haptic_configure(haptic, true); in max77693_haptic_enable()
184 haptic->enabled = true; in max77693_haptic_enable()
189 max77693_haptic_lowsys(haptic, false); in max77693_haptic_enable()
191 pwm_disable(haptic->pwm_dev); in max77693_haptic_enable()
194 static void max77693_haptic_disable(struct max77693_haptic *haptic) in max77693_haptic_disable() argument
198 if (!haptic->enabled) in max77693_haptic_disable()
201 error = max77693_haptic_configure(haptic, false); in max77693_haptic_disable()
205 error = max77693_haptic_lowsys(haptic, false); in max77693_haptic_disable()
209 pwm_disable(haptic->pwm_dev); in max77693_haptic_disable()
210 haptic->enabled = false; in max77693_haptic_disable()
215 max77693_haptic_configure(haptic, true); in max77693_haptic_disable()
220 struct max77693_haptic *haptic = in max77693_haptic_play_work() local
224 error = max77693_haptic_set_duty_cycle(haptic); in max77693_haptic_play_work()
226 dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); in max77693_haptic_play_work()
230 if (haptic->magnitude) in max77693_haptic_play_work()
231 max77693_haptic_enable(haptic); in max77693_haptic_play_work()
233 max77693_haptic_disable(haptic); in max77693_haptic_play_work()
239 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_play_effect() local
243 haptic->magnitude = effect->u.rumble.strong_magnitude; in max77693_haptic_play_effect()
244 if (!haptic->magnitude) in max77693_haptic_play_effect()
245 haptic->magnitude = effect->u.rumble.weak_magnitude; in max77693_haptic_play_effect()
252 pwm_get_args(haptic->pwm_dev, &pargs); in max77693_haptic_play_effect()
253 period_mag_multi = (u64)pargs.period * haptic->magnitude; in max77693_haptic_play_effect()
254 haptic->pwm_duty = (unsigned int)(period_mag_multi >> in max77693_haptic_play_effect()
257 schedule_work(&haptic->work); in max77693_haptic_play_effect()
264 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_open() local
267 error = max77843_haptic_bias(haptic, true); in max77693_haptic_open()
271 error = regulator_enable(haptic->motor_reg); in max77693_haptic_open()
273 dev_err(haptic->dev, in max77693_haptic_open()
283 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_close() local
286 cancel_work_sync(&haptic->work); in max77693_haptic_close()
287 max77693_haptic_disable(haptic); in max77693_haptic_close()
289 error = regulator_disable(haptic->motor_reg); in max77693_haptic_close()
291 dev_err(haptic->dev, in max77693_haptic_close()
294 max77843_haptic_bias(haptic, false); in max77693_haptic_close()
300 struct max77693_haptic *haptic; in max77693_haptic_probe() local
303 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in max77693_haptic_probe()
304 if (!haptic) in max77693_haptic_probe()
307 haptic->regmap_pmic = max77693->regmap; in max77693_haptic_probe()
308 haptic->dev = &pdev->dev; in max77693_haptic_probe()
309 haptic->type = MAX77693_HAPTIC_LRA; in max77693_haptic_probe()
310 haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; in max77693_haptic_probe()
311 haptic->suspend_state = false; in max77693_haptic_probe()
314 haptic->dev_type = platform_get_device_id(pdev)->driver_data; in max77693_haptic_probe()
315 switch (haptic->dev_type) { in max77693_haptic_probe()
317 haptic->regmap_haptic = max77693->regmap_haptic; in max77693_haptic_probe()
320 haptic->regmap_haptic = max77693->regmap; in max77693_haptic_probe()
324 haptic->dev_type); in max77693_haptic_probe()
328 INIT_WORK(&haptic->work, max77693_haptic_play_work); in max77693_haptic_probe()
331 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); in max77693_haptic_probe()
332 if (IS_ERR(haptic->pwm_dev)) { in max77693_haptic_probe()
334 return PTR_ERR(haptic->pwm_dev); in max77693_haptic_probe()
341 pwm_apply_args(haptic->pwm_dev); in max77693_haptic_probe()
343 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic"); in max77693_haptic_probe()
344 if (IS_ERR(haptic->motor_reg)) { in max77693_haptic_probe()
346 return PTR_ERR(haptic->motor_reg); in max77693_haptic_probe()
350 haptic->input_dev = devm_input_allocate_device(&pdev->dev); in max77693_haptic_probe()
351 if (!haptic->input_dev) { in max77693_haptic_probe()
356 haptic->input_dev->name = "max77693-haptic"; in max77693_haptic_probe()
357 haptic->input_dev->id.version = 1; in max77693_haptic_probe()
358 haptic->input_dev->dev.parent = &pdev->dev; in max77693_haptic_probe()
359 haptic->input_dev->open = max77693_haptic_open; in max77693_haptic_probe()
360 haptic->input_dev->close = max77693_haptic_close; in max77693_haptic_probe()
361 input_set_drvdata(haptic->input_dev, haptic); in max77693_haptic_probe()
362 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in max77693_haptic_probe()
364 error = input_ff_create_memless(haptic->input_dev, NULL, in max77693_haptic_probe()
371 error = input_register_device(haptic->input_dev); in max77693_haptic_probe()
377 platform_set_drvdata(pdev, haptic); in max77693_haptic_probe()
385 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_suspend() local
387 if (haptic->enabled) { in max77693_haptic_suspend()
388 max77693_haptic_disable(haptic); in max77693_haptic_suspend()
389 haptic->suspend_state = true; in max77693_haptic_suspend()
398 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_resume() local
400 if (haptic->suspend_state) { in max77693_haptic_resume()
401 max77693_haptic_enable(haptic); in max77693_haptic_resume()
402 haptic->suspend_state = false; in max77693_haptic_resume()