Lines Matching +full:regulator +full:- +full:haptic
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MAX8997-haptic controller driver
17 #include <linux/mfd/max8997-private.h>
19 #include <linux/regulator/consumer.h>
21 /* Haptic configuration 2 register */
26 /* Haptic driver configuration register */
36 struct regulator *regulator; member
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()
68 if (chip->level <= i * 100 / 64) { in max8997_haptic_set_duty_cycle()
73 switch (chip->internal_mode_pattern) { in max8997_haptic_set_duty_cycle()
75 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
79 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
83 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
87 max8997_write_reg(chip->client, in max8997_haptic_set_duty_cycle()
101 value = chip->type << MAX8997_MOTOR_TYPE_SHIFT | in max8997_haptic_configure()
102 chip->enabled << MAX8997_ENABLE_SHIFT | in max8997_haptic_configure()
103 chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor; in max8997_haptic_configure()
104 max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value); in max8997_haptic_configure()
106 if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) { in max8997_haptic_configure()
107 value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT | in max8997_haptic_configure()
108 chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT | in max8997_haptic_configure()
109 chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT | in max8997_haptic_configure()
110 chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT; in max8997_haptic_configure()
111 max8997_write_reg(chip->client, in max8997_haptic_configure()
114 switch (chip->internal_mode_pattern) { in max8997_haptic_configure()
116 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
117 max8997_write_reg(chip->client, in max8997_haptic_configure()
119 value = chip->pattern_signal_period; in max8997_haptic_configure()
120 max8997_write_reg(chip->client, in max8997_haptic_configure()
125 value = chip->pattern_cycle; in max8997_haptic_configure()
126 max8997_write_reg(chip->client, in max8997_haptic_configure()
128 value = chip->pattern_signal_period; in max8997_haptic_configure()
129 max8997_write_reg(chip->client, in max8997_haptic_configure()
134 value = chip->pattern_cycle << 4; in max8997_haptic_configure()
135 max8997_write_reg(chip->client, in max8997_haptic_configure()
137 value = chip->pattern_signal_period; in max8997_haptic_configure()
138 max8997_write_reg(chip->client, in max8997_haptic_configure()
143 value = chip->pattern_cycle; in max8997_haptic_configure()
144 max8997_write_reg(chip->client, in max8997_haptic_configure()
146 value = chip->pattern_signal_period; in max8997_haptic_configure()
147 max8997_write_reg(chip->client, in max8997_haptic_configure()
161 mutex_lock(&chip->mutex); in max8997_haptic_enable()
165 dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error); in max8997_haptic_enable()
169 if (!chip->enabled) { in max8997_haptic_enable()
170 error = regulator_enable(chip->regulator); in max8997_haptic_enable()
172 dev_err(chip->dev, "Failed to enable regulator\n"); in max8997_haptic_enable()
176 if (chip->mode == MAX8997_EXTERNAL_MODE) { in max8997_haptic_enable()
177 error = pwm_enable(chip->pwm); in max8997_haptic_enable()
179 dev_err(chip->dev, "Failed to enable PWM\n"); in max8997_haptic_enable()
180 regulator_disable(chip->regulator); in max8997_haptic_enable()
184 chip->enabled = true; in max8997_haptic_enable()
188 mutex_unlock(&chip->mutex); in max8997_haptic_enable()
193 mutex_lock(&chip->mutex); in max8997_haptic_disable()
195 if (chip->enabled) { in max8997_haptic_disable()
196 chip->enabled = false; in max8997_haptic_disable()
198 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_disable()
199 pwm_disable(chip->pwm); in max8997_haptic_disable()
200 regulator_disable(chip->regulator); in max8997_haptic_disable()
203 mutex_unlock(&chip->mutex); in max8997_haptic_disable()
211 if (chip->level) in max8997_haptic_play_effect_work()
222 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
223 if (!chip->level) in max8997_haptic_play_effect()
224 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
226 schedule_work(&chip->work); in max8997_haptic_play_effect()
235 cancel_work_sync(&chip->work); in max8997_haptic_close()
241 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_haptic_probe()
243 dev_get_platdata(iodev->dev); in max8997_haptic_probe()
250 haptic_pdata = pdata->haptic_pdata; in max8997_haptic_probe()
253 dev_err(&pdev->dev, "no haptic platform data\n"); in max8997_haptic_probe()
254 return -EINVAL; in max8997_haptic_probe()
260 dev_err(&pdev->dev, "unable to allocate memory\n"); in max8997_haptic_probe()
261 error = -ENOMEM; in max8997_haptic_probe()
265 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
266 mutex_init(&chip->mutex); in max8997_haptic_probe()
268 chip->client = iodev->haptic; in max8997_haptic_probe()
269 chip->dev = &pdev->dev; in max8997_haptic_probe()
270 chip->input_dev = input_dev; in max8997_haptic_probe()
271 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
272 chip->type = haptic_pdata->type; in max8997_haptic_probe()
273 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
274 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
276 switch (chip->mode) { in max8997_haptic_probe()
278 chip->internal_mode_pattern = in max8997_haptic_probe()
279 haptic_pdata->internal_mode_pattern; in max8997_haptic_probe()
280 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
281 chip->pattern_signal_period = in max8997_haptic_probe()
282 haptic_pdata->pattern_signal_period; in max8997_haptic_probe()
286 chip->pwm = pwm_request(haptic_pdata->pwm_channel_id, in max8997_haptic_probe()
287 "max8997-haptic"); in max8997_haptic_probe()
288 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
289 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
290 dev_err(&pdev->dev, in max8997_haptic_probe()
291 "unable to request PWM for haptic, error: %d\n", in max8997_haptic_probe()
300 pwm_apply_args(chip->pwm); in max8997_haptic_probe()
304 dev_err(&pdev->dev, in max8997_haptic_probe()
305 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
306 error = -EINVAL; in max8997_haptic_probe()
310 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
311 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
312 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
313 dev_err(&pdev->dev, in max8997_haptic_probe()
314 "unable to get regulator, error: %d\n", in max8997_haptic_probe()
319 input_dev->name = "max8997-haptic"; in max8997_haptic_probe()
320 input_dev->id.version = 1; in max8997_haptic_probe()
321 input_dev->dev.parent = &pdev->dev; in max8997_haptic_probe()
322 input_dev->close = max8997_haptic_close; in max8997_haptic_probe()
329 dev_err(&pdev->dev, in max8997_haptic_probe()
337 dev_err(&pdev->dev, in max8997_haptic_probe()
349 regulator_put(chip->regulator); in max8997_haptic_probe()
351 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
352 pwm_free(chip->pwm); in max8997_haptic_probe()
364 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
365 regulator_put(chip->regulator); in max8997_haptic_remove()
367 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
368 pwm_free(chip->pwm); in max8997_haptic_remove()
388 { "max8997-haptic", 0 },
395 .name = "max8997-haptic",