Lines Matching refs:haptic

71 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)  in max77693_haptic_set_duty_cycle()  argument
73 int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; in max77693_haptic_set_duty_cycle()
76 error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); in max77693_haptic_set_duty_cycle()
78 dev_err(haptic->dev, "failed to configure pwm: %d\n", error); in max77693_haptic_set_duty_cycle()
85 static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on) in max77843_haptic_bias() argument
89 if (haptic->dev_type != TYPE_MAX77843) in max77843_haptic_bias()
92 error = regmap_update_bits(haptic->regmap_haptic, in max77843_haptic_bias()
97 dev_err(haptic->dev, "failed to %s bias: %d\n", in max77843_haptic_bias()
105 static int max77693_haptic_configure(struct max77693_haptic *haptic, in max77693_haptic_configure() argument
111 switch (haptic->dev_type) { in max77693_haptic_configure()
113 value = ((haptic->type << MAX77693_CONFIG2_MODE) | in max77693_haptic_configure()
115 (haptic->mode << MAX77693_CONFIG2_HTYP) | in max77693_haptic_configure()
120 value = (haptic->type << MCONFIG_MODE_SHIFT) | in max77693_haptic_configure()
129 error = regmap_write(haptic->regmap_haptic, in max77693_haptic_configure()
132 dev_err(haptic->dev, in max77693_haptic_configure()
140 static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable) in max77693_haptic_lowsys() argument
144 if (haptic->dev_type != TYPE_MAX77693) in max77693_haptic_lowsys()
147 error = regmap_update_bits(haptic->regmap_pmic, in max77693_haptic_lowsys()
152 dev_err(haptic->dev, "cannot update pmic regmap: %d\n", error); in max77693_haptic_lowsys()
159 static void max77693_haptic_enable(struct max77693_haptic *haptic) in max77693_haptic_enable() argument
163 if (haptic->enabled) in max77693_haptic_enable()
166 error = pwm_enable(haptic->pwm_dev); in max77693_haptic_enable()
168 dev_err(haptic->dev, in max77693_haptic_enable()
173 error = max77693_haptic_lowsys(haptic, true); in max77693_haptic_enable()
177 error = max77693_haptic_configure(haptic, true); in max77693_haptic_enable()
181 haptic->enabled = true; in max77693_haptic_enable()
186 max77693_haptic_lowsys(haptic, false); in max77693_haptic_enable()
188 pwm_disable(haptic->pwm_dev); in max77693_haptic_enable()
191 static void max77693_haptic_disable(struct max77693_haptic *haptic) in max77693_haptic_disable() argument
195 if (!haptic->enabled) in max77693_haptic_disable()
198 error = max77693_haptic_configure(haptic, false); in max77693_haptic_disable()
202 error = max77693_haptic_lowsys(haptic, false); in max77693_haptic_disable()
206 pwm_disable(haptic->pwm_dev); in max77693_haptic_disable()
207 haptic->enabled = false; in max77693_haptic_disable()
212 max77693_haptic_configure(haptic, true); in max77693_haptic_disable()
217 struct max77693_haptic *haptic = in max77693_haptic_play_work() local
221 error = max77693_haptic_set_duty_cycle(haptic); in max77693_haptic_play_work()
223 dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); in max77693_haptic_play_work()
227 if (haptic->magnitude) in max77693_haptic_play_work()
228 max77693_haptic_enable(haptic); in max77693_haptic_play_work()
230 max77693_haptic_disable(haptic); in max77693_haptic_play_work()
236 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_play_effect() local
239 haptic->magnitude = effect->u.rumble.strong_magnitude; in max77693_haptic_play_effect()
240 if (!haptic->magnitude) in max77693_haptic_play_effect()
241 haptic->magnitude = effect->u.rumble.weak_magnitude; in max77693_haptic_play_effect()
248 period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude; in max77693_haptic_play_effect()
249 haptic->pwm_duty = (unsigned int)(period_mag_multi >> in max77693_haptic_play_effect()
252 schedule_work(&haptic->work); in max77693_haptic_play_effect()
259 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_open() local
262 error = max77843_haptic_bias(haptic, true); in max77693_haptic_open()
266 error = regulator_enable(haptic->motor_reg); in max77693_haptic_open()
268 dev_err(haptic->dev, in max77693_haptic_open()
278 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_close() local
281 cancel_work_sync(&haptic->work); in max77693_haptic_close()
282 max77693_haptic_disable(haptic); in max77693_haptic_close()
284 error = regulator_disable(haptic->motor_reg); in max77693_haptic_close()
286 dev_err(haptic->dev, in max77693_haptic_close()
289 max77843_haptic_bias(haptic, false); in max77693_haptic_close()
295 struct max77693_haptic *haptic; in max77693_haptic_probe() local
298 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in max77693_haptic_probe()
299 if (!haptic) in max77693_haptic_probe()
302 haptic->regmap_pmic = max77693->regmap; in max77693_haptic_probe()
303 haptic->dev = &pdev->dev; in max77693_haptic_probe()
304 haptic->type = MAX77693_HAPTIC_LRA; in max77693_haptic_probe()
305 haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; in max77693_haptic_probe()
306 haptic->suspend_state = false; in max77693_haptic_probe()
309 haptic->dev_type = platform_get_device_id(pdev)->driver_data; in max77693_haptic_probe()
310 switch (haptic->dev_type) { in max77693_haptic_probe()
312 haptic->regmap_haptic = max77693->regmap_haptic; in max77693_haptic_probe()
315 haptic->regmap_haptic = max77693->regmap; in max77693_haptic_probe()
319 haptic->dev_type); in max77693_haptic_probe()
323 INIT_WORK(&haptic->work, max77693_haptic_play_work); in max77693_haptic_probe()
326 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); in max77693_haptic_probe()
327 if (IS_ERR(haptic->pwm_dev)) { in max77693_haptic_probe()
329 return PTR_ERR(haptic->pwm_dev); in max77693_haptic_probe()
332 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic"); in max77693_haptic_probe()
333 if (IS_ERR(haptic->motor_reg)) { in max77693_haptic_probe()
335 return PTR_ERR(haptic->motor_reg); in max77693_haptic_probe()
339 haptic->input_dev = devm_input_allocate_device(&pdev->dev); in max77693_haptic_probe()
340 if (!haptic->input_dev) { in max77693_haptic_probe()
345 haptic->input_dev->name = "max77693-haptic"; in max77693_haptic_probe()
346 haptic->input_dev->id.version = 1; in max77693_haptic_probe()
347 haptic->input_dev->dev.parent = &pdev->dev; in max77693_haptic_probe()
348 haptic->input_dev->open = max77693_haptic_open; in max77693_haptic_probe()
349 haptic->input_dev->close = max77693_haptic_close; in max77693_haptic_probe()
350 input_set_drvdata(haptic->input_dev, haptic); in max77693_haptic_probe()
351 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in max77693_haptic_probe()
353 error = input_ff_create_memless(haptic->input_dev, NULL, in max77693_haptic_probe()
360 error = input_register_device(haptic->input_dev); in max77693_haptic_probe()
366 platform_set_drvdata(pdev, haptic); in max77693_haptic_probe()
374 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_suspend() local
376 if (haptic->enabled) { in max77693_haptic_suspend()
377 max77693_haptic_disable(haptic); in max77693_haptic_suspend()
378 haptic->suspend_state = true; in max77693_haptic_suspend()
387 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_resume() local
389 if (haptic->suspend_state) { in max77693_haptic_resume()
390 max77693_haptic_enable(haptic); in max77693_haptic_resume()
391 haptic->suspend_state = false; in max77693_haptic_resume()