Lines Matching refs:haptic

67 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)  in max77693_haptic_set_duty_cycle()  argument
69 int delta = (haptic->pwm_dev->period + haptic->pwm_duty) / 2; in max77693_haptic_set_duty_cycle()
72 error = pwm_config(haptic->pwm_dev, delta, haptic->pwm_dev->period); in max77693_haptic_set_duty_cycle()
74 dev_err(haptic->dev, "failed to configure pwm: %d\n", error); in max77693_haptic_set_duty_cycle()
81 static int max77693_haptic_configure(struct max77693_haptic *haptic, in max77693_haptic_configure() argument
87 value = ((haptic->type << MAX77693_CONFIG2_MODE) | in max77693_haptic_configure()
89 (haptic->mode << MAX77693_CONFIG2_HTYP) | in max77693_haptic_configure()
90 (haptic->pwm_divisor)); in max77693_haptic_configure()
92 error = regmap_write(haptic->regmap_haptic, in max77693_haptic_configure()
95 dev_err(haptic->dev, in max77693_haptic_configure()
103 static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable) in max77693_haptic_lowsys() argument
107 error = regmap_update_bits(haptic->regmap_pmic, in max77693_haptic_lowsys()
112 dev_err(haptic->dev, "cannot update pmic regmap: %d\n", error); in max77693_haptic_lowsys()
119 static void max77693_haptic_enable(struct max77693_haptic *haptic) in max77693_haptic_enable() argument
123 if (haptic->enabled) in max77693_haptic_enable()
126 error = pwm_enable(haptic->pwm_dev); in max77693_haptic_enable()
128 dev_err(haptic->dev, in max77693_haptic_enable()
133 error = max77693_haptic_lowsys(haptic, true); in max77693_haptic_enable()
137 error = max77693_haptic_configure(haptic, true); in max77693_haptic_enable()
141 haptic->enabled = true; in max77693_haptic_enable()
146 max77693_haptic_lowsys(haptic, false); in max77693_haptic_enable()
148 pwm_disable(haptic->pwm_dev); in max77693_haptic_enable()
151 static void max77693_haptic_disable(struct max77693_haptic *haptic) in max77693_haptic_disable() argument
155 if (!haptic->enabled) in max77693_haptic_disable()
158 error = max77693_haptic_configure(haptic, false); in max77693_haptic_disable()
162 error = max77693_haptic_lowsys(haptic, false); in max77693_haptic_disable()
166 pwm_disable(haptic->pwm_dev); in max77693_haptic_disable()
167 haptic->enabled = false; in max77693_haptic_disable()
172 max77693_haptic_configure(haptic, true); in max77693_haptic_disable()
177 struct max77693_haptic *haptic = in max77693_haptic_play_work() local
181 error = max77693_haptic_set_duty_cycle(haptic); in max77693_haptic_play_work()
183 dev_err(haptic->dev, "failed to set duty cycle: %d\n", error); in max77693_haptic_play_work()
187 if (haptic->magnitude) in max77693_haptic_play_work()
188 max77693_haptic_enable(haptic); in max77693_haptic_play_work()
190 max77693_haptic_disable(haptic); in max77693_haptic_play_work()
196 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_play_effect() local
199 haptic->magnitude = effect->u.rumble.strong_magnitude; in max77693_haptic_play_effect()
200 if (!haptic->magnitude) in max77693_haptic_play_effect()
201 haptic->magnitude = effect->u.rumble.weak_magnitude; in max77693_haptic_play_effect()
208 period_mag_multi = (u64)haptic->pwm_dev->period * haptic->magnitude; in max77693_haptic_play_effect()
209 haptic->pwm_duty = (unsigned int)(period_mag_multi >> in max77693_haptic_play_effect()
212 schedule_work(&haptic->work); in max77693_haptic_play_effect()
219 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_open() local
222 error = regulator_enable(haptic->motor_reg); in max77693_haptic_open()
224 dev_err(haptic->dev, in max77693_haptic_open()
234 struct max77693_haptic *haptic = input_get_drvdata(dev); in max77693_haptic_close() local
237 cancel_work_sync(&haptic->work); in max77693_haptic_close()
238 max77693_haptic_disable(haptic); in max77693_haptic_close()
240 error = regulator_disable(haptic->motor_reg); in max77693_haptic_close()
242 dev_err(haptic->dev, in max77693_haptic_close()
249 struct max77693_haptic *haptic; in max77693_haptic_probe() local
252 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in max77693_haptic_probe()
253 if (!haptic) in max77693_haptic_probe()
256 haptic->regmap_pmic = max77693->regmap; in max77693_haptic_probe()
257 haptic->regmap_haptic = max77693->regmap_haptic; in max77693_haptic_probe()
258 haptic->dev = &pdev->dev; in max77693_haptic_probe()
259 haptic->type = MAX77693_HAPTIC_LRA; in max77693_haptic_probe()
260 haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE; in max77693_haptic_probe()
261 haptic->pwm_divisor = MAX77693_HAPTIC_PWM_DIVISOR_128; in max77693_haptic_probe()
262 haptic->suspend_state = false; in max77693_haptic_probe()
264 INIT_WORK(&haptic->work, max77693_haptic_play_work); in max77693_haptic_probe()
267 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL); in max77693_haptic_probe()
268 if (IS_ERR(haptic->pwm_dev)) { in max77693_haptic_probe()
270 return PTR_ERR(haptic->pwm_dev); in max77693_haptic_probe()
273 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic"); in max77693_haptic_probe()
274 if (IS_ERR(haptic->motor_reg)) { in max77693_haptic_probe()
276 return PTR_ERR(haptic->motor_reg); in max77693_haptic_probe()
280 haptic->input_dev = devm_input_allocate_device(&pdev->dev); in max77693_haptic_probe()
281 if (!haptic->input_dev) { in max77693_haptic_probe()
286 haptic->input_dev->name = "max77693-haptic"; in max77693_haptic_probe()
287 haptic->input_dev->id.version = 1; in max77693_haptic_probe()
288 haptic->input_dev->dev.parent = &pdev->dev; in max77693_haptic_probe()
289 haptic->input_dev->open = max77693_haptic_open; in max77693_haptic_probe()
290 haptic->input_dev->close = max77693_haptic_close; in max77693_haptic_probe()
291 input_set_drvdata(haptic->input_dev, haptic); in max77693_haptic_probe()
292 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in max77693_haptic_probe()
294 error = input_ff_create_memless(haptic->input_dev, NULL, in max77693_haptic_probe()
301 error = input_register_device(haptic->input_dev); in max77693_haptic_probe()
307 platform_set_drvdata(pdev, haptic); in max77693_haptic_probe()
315 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_suspend() local
317 if (haptic->enabled) { in max77693_haptic_suspend()
318 max77693_haptic_disable(haptic); in max77693_haptic_suspend()
319 haptic->suspend_state = true; in max77693_haptic_suspend()
328 struct max77693_haptic *haptic = platform_get_drvdata(pdev); in max77693_haptic_resume() local
330 if (haptic->suspend_state) { in max77693_haptic_resume()
331 max77693_haptic_enable(haptic); in max77693_haptic_resume()
332 haptic->suspend_state = false; in max77693_haptic_resume()