Lines Matching +full:straight +full:- +full:forward
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MAX8997-haptic controller driver
17 #include <linux/mfd/max8997-private.h>
58 u8 duty_index = DIV_ROUND_UP(chip->level * 64, 100); in max8997_haptic_set_internal_duty_cycle()
60 switch (chip->internal_mode_pattern) { in max8997_haptic_set_internal_duty_cycle()
62 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
66 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
70 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
74 max8997_write_reg(chip->client, in max8997_haptic_set_internal_duty_cycle()
86 value = chip->type << MAX8997_MOTOR_TYPE_SHIFT | in max8997_haptic_configure()
87 chip->enabled << MAX8997_ENABLE_SHIFT | in max8997_haptic_configure()
88 chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor; in max8997_haptic_configure()
89 max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value); in max8997_haptic_configure()
91 if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) { in max8997_haptic_configure()
92 value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT | in max8997_haptic_configure()
93 chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT | in max8997_haptic_configure()
94 chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT | in max8997_haptic_configure()
95 chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT; in max8997_haptic_configure()
96 max8997_write_reg(chip->client, in max8997_haptic_configure()
99 switch (chip->internal_mode_pattern) { in max8997_haptic_configure()
101 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
102 max8997_write_reg(chip->client, in max8997_haptic_configure()
104 value = chip->pattern_signal_period; in max8997_haptic_configure()
105 max8997_write_reg(chip->client, in max8997_haptic_configure()
110 value = chip->pattern_cycle; in max8997_haptic_configure()
111 max8997_write_reg(chip->client, in max8997_haptic_configure()
113 value = chip->pattern_signal_period; in max8997_haptic_configure()
114 max8997_write_reg(chip->client, in max8997_haptic_configure()
119 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
120 max8997_write_reg(chip->client, in max8997_haptic_configure()
122 value = chip->pattern_signal_period; in max8997_haptic_configure()
123 max8997_write_reg(chip->client, in max8997_haptic_configure()
128 value = chip->pattern_cycle; in max8997_haptic_configure()
129 max8997_write_reg(chip->client, in max8997_haptic_configure()
131 value = chip->pattern_signal_period; in max8997_haptic_configure()
132 max8997_write_reg(chip->client, in max8997_haptic_configure()
146 guard(mutex)(&chip->mutex); in max8997_haptic_enable()
148 if (chip->mode != MAX8997_EXTERNAL_MODE) in max8997_haptic_enable()
151 if (!chip->enabled) { in max8997_haptic_enable()
152 error = regulator_enable(chip->regulator); in max8997_haptic_enable()
154 dev_err(chip->dev, "Failed to enable regulator\n"); in max8997_haptic_enable()
161 * It would be more straight forward to configure the external PWM in max8997_haptic_enable()
167 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_enable()
170 pwm_init_state(chip->pwm, &state); in max8997_haptic_enable()
171 state.period = chip->pwm_period; in max8997_haptic_enable()
172 state.duty_cycle = chip->pwm_period * chip->level / 100; in max8997_haptic_enable()
175 error = pwm_apply_might_sleep(chip->pwm, &state); in max8997_haptic_enable()
177 dev_err(chip->dev, "Failed to enable PWM\n"); in max8997_haptic_enable()
178 regulator_disable(chip->regulator); in max8997_haptic_enable()
183 chip->enabled = true; in max8997_haptic_enable()
188 guard(mutex)(&chip->mutex); in max8997_haptic_disable()
190 if (chip->enabled) { in max8997_haptic_disable()
191 chip->enabled = false; in max8997_haptic_disable()
193 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_disable()
194 pwm_disable(chip->pwm); in max8997_haptic_disable()
195 regulator_disable(chip->regulator); in max8997_haptic_disable()
204 if (chip->level) in max8997_haptic_play_effect_work()
215 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
216 if (!chip->level) in max8997_haptic_play_effect()
217 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
219 schedule_work(&chip->work); in max8997_haptic_play_effect()
228 cancel_work_sync(&chip->work); in max8997_haptic_close()
234 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_haptic_probe()
236 dev_get_platdata(iodev->dev); in max8997_haptic_probe()
243 haptic_pdata = pdata->haptic_pdata; in max8997_haptic_probe()
246 dev_err(&pdev->dev, "no haptic platform data\n"); in max8997_haptic_probe()
247 return -EINVAL; in max8997_haptic_probe()
253 dev_err(&pdev->dev, "unable to allocate memory\n"); in max8997_haptic_probe()
254 error = -ENOMEM; in max8997_haptic_probe()
258 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
259 mutex_init(&chip->mutex); in max8997_haptic_probe()
261 chip->client = iodev->haptic; in max8997_haptic_probe()
262 chip->dev = &pdev->dev; in max8997_haptic_probe()
263 chip->input_dev = input_dev; in max8997_haptic_probe()
264 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
265 chip->type = haptic_pdata->type; in max8997_haptic_probe()
266 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
267 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
269 switch (chip->mode) { in max8997_haptic_probe()
271 chip->internal_mode_pattern = in max8997_haptic_probe()
272 haptic_pdata->internal_mode_pattern; in max8997_haptic_probe()
273 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
274 chip->pattern_signal_period = in max8997_haptic_probe()
275 haptic_pdata->pattern_signal_period; in max8997_haptic_probe()
279 chip->pwm = pwm_get(&pdev->dev, NULL); in max8997_haptic_probe()
280 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
281 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
282 dev_err(&pdev->dev, in max8997_haptic_probe()
291 dev_err(&pdev->dev, in max8997_haptic_probe()
292 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
293 error = -EINVAL; in max8997_haptic_probe()
297 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
298 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
299 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
300 dev_err(&pdev->dev, in max8997_haptic_probe()
306 input_dev->name = "max8997-haptic"; in max8997_haptic_probe()
307 input_dev->id.version = 1; in max8997_haptic_probe()
308 input_dev->dev.parent = &pdev->dev; in max8997_haptic_probe()
309 input_dev->close = max8997_haptic_close; in max8997_haptic_probe()
316 dev_err(&pdev->dev, in max8997_haptic_probe()
324 dev_err(&pdev->dev, in max8997_haptic_probe()
336 regulator_put(chip->regulator); in max8997_haptic_probe()
338 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
339 pwm_put(chip->pwm); in max8997_haptic_probe()
351 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
352 regulator_put(chip->regulator); in max8997_haptic_remove()
354 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
355 pwm_put(chip->pwm); in max8997_haptic_remove()
374 { "max8997-haptic", 0 },
381 .name = "max8997-haptic",