Lines Matching +full:pwm +full:- +full:regulator
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * MAX8997-haptic controller driver
15 #include <linux/pwm.h>
17 #include <linux/mfd/max8997-private.h>
19 #include <linux/regulator/consumer.h>
36 struct regulator *regulator; member
44 struct pwm_device *pwm; 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()
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 mutex_lock(&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()
183 mutex_unlock(&chip->mutex); in max8997_haptic_enable()
188 mutex_lock(&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()
198 mutex_unlock(&chip->mutex); in max8997_haptic_disable()
206 if (chip->level) in max8997_haptic_play_effect_work()
217 chip->level = effect->u.rumble.strong_magnitude; in max8997_haptic_play_effect()
218 if (!chip->level) in max8997_haptic_play_effect()
219 chip->level = effect->u.rumble.weak_magnitude; in max8997_haptic_play_effect()
221 schedule_work(&chip->work); in max8997_haptic_play_effect()
230 cancel_work_sync(&chip->work); in max8997_haptic_close()
236 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent); in max8997_haptic_probe()
238 dev_get_platdata(iodev->dev); in max8997_haptic_probe()
245 haptic_pdata = pdata->haptic_pdata; in max8997_haptic_probe()
248 dev_err(&pdev->dev, "no haptic platform data\n"); in max8997_haptic_probe()
249 return -EINVAL; in max8997_haptic_probe()
255 dev_err(&pdev->dev, "unable to allocate memory\n"); in max8997_haptic_probe()
256 error = -ENOMEM; in max8997_haptic_probe()
260 INIT_WORK(&chip->work, max8997_haptic_play_effect_work); in max8997_haptic_probe()
261 mutex_init(&chip->mutex); in max8997_haptic_probe()
263 chip->client = iodev->haptic; in max8997_haptic_probe()
264 chip->dev = &pdev->dev; in max8997_haptic_probe()
265 chip->input_dev = input_dev; in max8997_haptic_probe()
266 chip->pwm_period = haptic_pdata->pwm_period; in max8997_haptic_probe()
267 chip->type = haptic_pdata->type; in max8997_haptic_probe()
268 chip->mode = haptic_pdata->mode; in max8997_haptic_probe()
269 chip->pwm_divisor = haptic_pdata->pwm_divisor; in max8997_haptic_probe()
271 switch (chip->mode) { in max8997_haptic_probe()
273 chip->internal_mode_pattern = in max8997_haptic_probe()
274 haptic_pdata->internal_mode_pattern; in max8997_haptic_probe()
275 chip->pattern_cycle = haptic_pdata->pattern_cycle; in max8997_haptic_probe()
276 chip->pattern_signal_period = in max8997_haptic_probe()
277 haptic_pdata->pattern_signal_period; in max8997_haptic_probe()
281 chip->pwm = pwm_get(&pdev->dev, NULL); in max8997_haptic_probe()
282 if (IS_ERR(chip->pwm)) { in max8997_haptic_probe()
283 error = PTR_ERR(chip->pwm); in max8997_haptic_probe()
284 dev_err(&pdev->dev, in max8997_haptic_probe()
285 "unable to request PWM for haptic, error: %d\n", in max8997_haptic_probe()
292 * the atomic PWM API. in max8997_haptic_probe()
294 pwm_apply_args(chip->pwm); in max8997_haptic_probe()
298 dev_err(&pdev->dev, in max8997_haptic_probe()
299 "Invalid chip mode specified (%d)\n", chip->mode); in max8997_haptic_probe()
300 error = -EINVAL; in max8997_haptic_probe()
304 chip->regulator = regulator_get(&pdev->dev, "inmotor"); in max8997_haptic_probe()
305 if (IS_ERR(chip->regulator)) { in max8997_haptic_probe()
306 error = PTR_ERR(chip->regulator); in max8997_haptic_probe()
307 dev_err(&pdev->dev, in max8997_haptic_probe()
308 "unable to get regulator, error: %d\n", in max8997_haptic_probe()
313 input_dev->name = "max8997-haptic"; in max8997_haptic_probe()
314 input_dev->id.version = 1; in max8997_haptic_probe()
315 input_dev->dev.parent = &pdev->dev; in max8997_haptic_probe()
316 input_dev->close = max8997_haptic_close; in max8997_haptic_probe()
323 dev_err(&pdev->dev, in max8997_haptic_probe()
331 dev_err(&pdev->dev, in max8997_haptic_probe()
343 regulator_put(chip->regulator); in max8997_haptic_probe()
345 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_probe()
346 pwm_put(chip->pwm); in max8997_haptic_probe()
358 input_unregister_device(chip->input_dev); in max8997_haptic_remove()
359 regulator_put(chip->regulator); in max8997_haptic_remove()
361 if (chip->mode == MAX8997_EXTERNAL_MODE) in max8997_haptic_remove()
362 pwm_put(chip->pwm); in max8997_haptic_remove()
383 { "max8997-haptic", 0 },
390 .name = "max8997-haptic",