Lines Matching +full:haptic +full:- +full:driver
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MAX8997-haptic controller driver
17 #include <linux/mfd/max8997-private.h>
21 /* Haptic configuration 2 register */
26 /* Haptic driver configuration register */
60 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_set_duty_cycle()
61 unsigned int duty = chip->pwm_period * chip->level / 100; in max8997_haptic_set_duty_cycle()
62 ret = pwm_config(chip->pwm, duty, chip->pwm_period); in max8997_haptic_set_duty_cycle()
66 duty_index = DIV_ROUND_UP(chip->level * 64, 100); in max8997_haptic_set_duty_cycle()
68 switch (chip->internal_mode_pattern) { in max8997_haptic_set_duty_cycle()
70 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
74 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
78 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
82 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
96 value = chip->type << MAX8997_MOTOR_TYPE_SHIFT | in max8997_haptic_configure()
97 chip->enabled << MAX8997_ENABLE_SHIFT | in max8997_haptic_configure()
98 chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor; in max8997_haptic_configure()
99 max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value); in max8997_haptic_configure()
101 if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) { in max8997_haptic_configure()
102 value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT | in max8997_haptic_configure()
103 chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT | in max8997_haptic_configure()
104 chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT | in max8997_haptic_configure()
105 chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT; in max8997_haptic_configure()
106 max8997_write_reg(chip->client, in max8997_haptic_configure()
109 switch (chip->internal_mode_pattern) { in max8997_haptic_configure()
111 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
112 max8997_write_reg(chip->client, in max8997_haptic_configure()
114 value = chip->pattern_signal_period; in max8997_haptic_configure()
115 max8997_write_reg(chip->client, in max8997_haptic_configure()
120 value = chip->pattern_cycle; in max8997_haptic_configure()
121 max8997_write_reg(chip->client, in max8997_haptic_configure()
123 value = chip->pattern_signal_period; in max8997_haptic_configure()
124 max8997_write_reg(chip->client, in max8997_haptic_configure()
129 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
130 max8997_write_reg(chip->client, in max8997_haptic_configure()
132 value = chip->pattern_signal_period; in max8997_haptic_configure()
133 max8997_write_reg(chip->client, in max8997_haptic_configure()
138 value = chip->pattern_cycle; in max8997_haptic_configure()
139 max8997_write_reg(chip->client, in max8997_haptic_configure()
141 value = chip->pattern_signal_period; in max8997_haptic_configure()
142 max8997_write_reg(chip->client, in max8997_haptic_configure()
156 guard(mutex)(&chip->mutex); in max8997_haptic_enable()
160 dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error); in max8997_haptic_enable()
164 if (!chip->enabled) { in max8997_haptic_enable()
165 error = regulator_enable(chip->regulator); in max8997_haptic_enable()
167 dev_err(chip->dev, "Failed to enable regulator\n"); in max8997_haptic_enable()
171 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_enable()
172 error = pwm_enable(chip->pwm); in max8997_haptic_enable()
174 dev_err(chip->dev, "Failed to enable PWM\n"); in max8997_haptic_enable()
175 regulator_disable(chip->regulator); in max8997_haptic_enable()
179 chip->enabled = true; in max8997_haptic_enable()
185 guard(mutex)(&chip->mutex); in max8997_haptic_disable()
187 if (chip->enabled) { in max8997_haptic_disable()
188 chip->enabled = false; in max8997_haptic_disable()
190 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_disable()
191 pwm_disable(chip->pwm); in max8997_haptic_disable()
192 regulator_disable(chip->regulator); in max8997_haptic_disable()
201 if (chip->level) in max8997_haptic_play_effect_work()
212 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
213 if (!chip->level) in max8997_haptic_play_effect()
214 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
216 schedule_work(&chip->work); in max8997_haptic_play_effect()
225 cancel_work_sync(&chip->work); in max8997_haptic_close()
231 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_haptic_probe()
233 dev_get_platdata(iodev->dev); in max8997_haptic_probe()
240 haptic_pdata = pdata->haptic_pdata; in max8997_haptic_probe()
243 dev_err(&pdev->dev, "no haptic platform data\n"); in max8997_haptic_probe()
244 return -EINVAL; in max8997_haptic_probe()
250 dev_err(&pdev->dev, "unable to allocate memory\n"); in max8997_haptic_probe()
251 error = -ENOMEM; in max8997_haptic_probe()
255 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
256 mutex_init(&chip->mutex); in max8997_haptic_probe()
258 chip->client = iodev->haptic; in max8997_haptic_probe()
259 chip->dev = &pdev->dev; in max8997_haptic_probe()
260 chip->input_dev = input_dev; in max8997_haptic_probe()
261 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
262 chip->type = haptic_pdata->type; in max8997_haptic_probe()
263 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
264 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
266 switch (chip->mode) { in max8997_haptic_probe()
268 chip->internal_mode_pattern = in max8997_haptic_probe()
269 haptic_pdata->internal_mode_pattern; in max8997_haptic_probe()
270 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
271 chip->pattern_signal_period = in max8997_haptic_probe()
272 haptic_pdata->pattern_signal_period; in max8997_haptic_probe()
276 chip->pwm = pwm_get(&pdev->dev, NULL); in max8997_haptic_probe()
277 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
278 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
279 dev_err(&pdev->dev, in max8997_haptic_probe()
280 "unable to request PWM for haptic, error: %d\n", in max8997_haptic_probe()
289 pwm_apply_args(chip->pwm); in max8997_haptic_probe()
293 dev_err(&pdev->dev, in max8997_haptic_probe()
294 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
295 error = -EINVAL; in max8997_haptic_probe()
299 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
300 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
301 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
302 dev_err(&pdev->dev, in max8997_haptic_probe()
308 input_dev->name = "max8997-haptic"; in max8997_haptic_probe()
309 input_dev->id.version = 1; in max8997_haptic_probe()
310 input_dev->dev.parent = &pdev->dev; in max8997_haptic_probe()
311 input_dev->close = max8997_haptic_close; in max8997_haptic_probe()
318 dev_err(&pdev->dev, in max8997_haptic_probe()
326 dev_err(&pdev->dev, in max8997_haptic_probe()
338 regulator_put(chip->regulator); in max8997_haptic_probe()
340 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
341 pwm_put(chip->pwm); in max8997_haptic_probe()
353 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
354 regulator_put(chip->regulator); in max8997_haptic_remove()
356 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
357 pwm_put(chip->pwm); in max8997_haptic_remove()
376 { "max8997-haptic", 0 },
382 .driver = {
383 .name = "max8997-haptic",
393 MODULE_DESCRIPTION("max8997_haptic driver");