Lines Matching refs:haptic

67 static int max77693_haptic_set_duty_cycle(struct max77693_haptic *haptic)
73 pwm_get_args(haptic->pwm_dev, &pargs);
74 delta = (pargs.period + haptic->pwm_duty) / 2;
75 error = pwm_config(haptic->pwm_dev, delta, pargs.period);
77 dev_err(haptic->dev, "failed to configure pwm: %d\n", error);
84 static int max77843_haptic_bias(struct max77693_haptic *haptic, bool on)
88 if (haptic->dev_type != TYPE_MAX77843)
91 error = regmap_update_bits(haptic->regmap_haptic,
96 dev_err(haptic->dev, "failed to %s bias: %d\n",
104 static int max77693_haptic_configure(struct max77693_haptic *haptic,
110 switch (haptic->dev_type) {
112 value = ((haptic->type << MAX77693_CONFIG2_MODE) |
114 (haptic->mode << MAX77693_CONFIG2_HTYP) |
119 value = (haptic->type << MCONFIG_MODE_SHIFT) |
128 error = regmap_write(haptic->regmap_haptic,
131 dev_err(haptic->dev,
132 "failed to update haptic config: %d\n", error);
139 static int max77693_haptic_lowsys(struct max77693_haptic *haptic, bool enable)
143 if (haptic->dev_type != TYPE_MAX77693)
146 error = regmap_update_bits(haptic->regmap_pmic,
151 dev_err(haptic->dev, "cannot update pmic regmap: %d\n", error);
158 static void max77693_haptic_enable(struct max77693_haptic *haptic)
162 if (haptic->enabled)
165 error = pwm_enable(haptic->pwm_dev);
167 dev_err(haptic->dev,
168 "failed to enable haptic pwm device: %d\n", error);
172 error = max77693_haptic_lowsys(haptic, true);
176 error = max77693_haptic_configure(haptic, true);
180 haptic->enabled = true;
185 max77693_haptic_lowsys(haptic, false);
187 pwm_disable(haptic->pwm_dev);
190 static void max77693_haptic_disable(struct max77693_haptic *haptic)
194 if (!haptic->enabled)
197 error = max77693_haptic_configure(haptic, false);
201 error = max77693_haptic_lowsys(haptic, false);
205 pwm_disable(haptic->pwm_dev);
206 haptic->enabled = false;
211 max77693_haptic_configure(haptic, true);
216 struct max77693_haptic *haptic =
220 error = max77693_haptic_set_duty_cycle(haptic);
222 dev_err(haptic->dev, "failed to set duty cycle: %d\n", error);
226 if (haptic->magnitude)
227 max77693_haptic_enable(haptic);
229 max77693_haptic_disable(haptic);
235 struct max77693_haptic *haptic = input_get_drvdata(dev);
239 haptic->magnitude = effect->u.rumble.strong_magnitude;
240 if (!haptic->magnitude)
241 haptic->magnitude = effect->u.rumble.weak_magnitude;
248 pwm_get_args(haptic->pwm_dev, &pargs);
249 period_mag_multi = (u64)pargs.period * haptic->magnitude;
250 haptic->pwm_duty = (unsigned int)(period_mag_multi >>
253 schedule_work(&haptic->work);
260 struct max77693_haptic *haptic = input_get_drvdata(dev);
263 error = max77843_haptic_bias(haptic, true);
267 error = regulator_enable(haptic->motor_reg);
269 dev_err(haptic->dev,
279 struct max77693_haptic *haptic = input_get_drvdata(dev);
282 cancel_work_sync(&haptic->work);
283 max77693_haptic_disable(haptic);
285 error = regulator_disable(haptic->motor_reg);
287 dev_err(haptic->dev,
290 max77843_haptic_bias(haptic, false);
296 struct max77693_haptic *haptic;
299 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL);
300 if (!haptic)
303 haptic->regmap_pmic = max77693->regmap;
304 haptic->dev = &pdev->dev;
305 haptic->type = MAX77693_HAPTIC_LRA;
306 haptic->mode = MAX77693_HAPTIC_EXTERNAL_MODE;
307 haptic->suspend_state = false;
310 haptic->dev_type = platform_get_device_id(pdev)->driver_data;
311 switch (haptic->dev_type) {
313 haptic->regmap_haptic = max77693->regmap_haptic;
316 haptic->regmap_haptic = max77693->regmap;
320 haptic->dev_type);
324 INIT_WORK(&haptic->work, max77693_haptic_play_work);
326 /* Get pwm and regulatot for haptic device */
327 haptic->pwm_dev = devm_pwm_get(&pdev->dev, NULL);
328 if (IS_ERR(haptic->pwm_dev)) {
330 return PTR_ERR(haptic->pwm_dev);
337 pwm_apply_args(haptic->pwm_dev);
339 haptic->motor_reg = devm_regulator_get(&pdev->dev, "haptic");
340 if (IS_ERR(haptic->motor_reg)) {
342 return PTR_ERR(haptic->motor_reg);
345 /* Initialize input device for haptic device */
346 haptic->input_dev = devm_input_allocate_device(&pdev->dev);
347 if (!haptic->input_dev) {
352 haptic->input_dev->name = "max77693-haptic";
353 haptic->input_dev->id.version = 1;
354 haptic->input_dev->dev.parent = &pdev->dev;
355 haptic->input_dev->open = max77693_haptic_open;
356 haptic->input_dev->close = max77693_haptic_close;
357 input_set_drvdata(haptic->input_dev, haptic);
358 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE);
360 error = input_ff_create_memless(haptic->input_dev, NULL,
367 error = input_register_device(haptic->input_dev);
373 platform_set_drvdata(pdev, haptic);
381 struct max77693_haptic *haptic = platform_get_drvdata(pdev);
383 if (haptic->enabled) {
384 max77693_haptic_disable(haptic);
385 haptic->suspend_state = true;
394 struct max77693_haptic *haptic = platform_get_drvdata(pdev);
396 if (haptic->suspend_state) {
397 max77693_haptic_enable(haptic);
398 haptic->suspend_state = false;
409 { "max77693-haptic", TYPE_MAX77693 },
410 { "max77843-haptic", TYPE_MAX77843 },
417 .name = "max77693-haptic",