Lines Matching +full:motor +full:- +full:driver

1 // SPDX-License-Identifier: GPL-2.0-only
3 * twl6040-vibra.c - TWL6040 Vibrator driver
10 * Based on twl4030-vibra.c by Henrik Saari <henrik.saari@nokia.com>
12 * Jari Vanhala <ext-javi.vanhala@nokia.com>
56 struct twl6040 *twl6040 = info->twl6040; in twl6040_vib_irq_handler()
61 dev_warn(info->dev, "Left Vibrator overcurrent detected\n"); in twl6040_vib_irq_handler()
66 dev_warn(info->dev, "Right Vibrator overcurrent detected\n"); in twl6040_vib_irq_handler()
76 struct twl6040 *twl6040 = info->twl6040; in twl6040_vibra_enable()
79 ret = regulator_bulk_enable(ARRAY_SIZE(info->supplies), info->supplies); in twl6040_vibra_enable()
81 dev_err(info->dev, "failed to enable regulators %d\n", ret); in twl6040_vibra_enable()
85 twl6040_power(info->twl6040, 1); in twl6040_vibra_enable()
104 info->enabled = true; in twl6040_vibra_enable()
109 struct twl6040 *twl6040 = info->twl6040; in twl6040_vibra_disable()
113 twl6040_power(info->twl6040, 0); in twl6040_vibra_disable()
115 regulator_bulk_disable(ARRAY_SIZE(info->supplies), info->supplies); in twl6040_vibra_disable()
117 info->enabled = false; in twl6040_vibra_disable()
146 struct twl6040 *twl6040 = info->twl6040; in twl6040_vibra_set_effect()
150 /* weak motor */ in twl6040_vibra_set_effect()
151 volt = regulator_get_voltage(info->supplies[0].consumer) / 1000; in twl6040_vibra_set_effect()
152 vibdatl = twl6040_vibra_code(volt, info->vibldrv_res, in twl6040_vibra_set_effect()
153 info->viblmotor_res, in twl6040_vibra_set_effect()
154 info->weak_speed, info->direction); in twl6040_vibra_set_effect()
156 /* strong motor */ in twl6040_vibra_set_effect()
157 volt = regulator_get_voltage(info->supplies[1].consumer) / 1000; in twl6040_vibra_set_effect()
158 vibdatr = twl6040_vibra_code(volt, info->vibrdrv_res, in twl6040_vibra_set_effect()
159 info->vibrmotor_res, in twl6040_vibra_set_effect()
160 info->strong_speed, info->direction); in twl6040_vibra_set_effect()
173 ret = twl6040_get_vibralr_status(info->twl6040); in vibra_play_work()
175 dev_info(info->dev, "Vibra is configured for audio\n"); in vibra_play_work()
179 if (info->weak_speed || info->strong_speed) { in vibra_play_work()
180 if (!info->enabled) in vibra_play_work()
184 } else if (info->enabled) in vibra_play_work()
194 info->weak_speed = effect->u.rumble.weak_magnitude; in vibra_play()
195 info->strong_speed = effect->u.rumble.strong_magnitude; in vibra_play()
196 info->direction = effect->direction < EFFECT_DIR_180_DEG ? 1 : -1; in vibra_play()
198 schedule_work(&info->play_work); in vibra_play()
207 cancel_work_sync(&info->play_work); in twl6040_vibra_close()
209 if (info->enabled) in twl6040_vibra_close()
218 cancel_work_sync(&info->play_work); in twl6040_vibra_suspend()
220 if (info->enabled) in twl6040_vibra_suspend()
230 struct device *twl6040_core_dev = pdev->dev.parent; in twl6040_vibra_probe()
237 twl6040_core_node = of_get_child_by_name(twl6040_core_dev->of_node, in twl6040_vibra_probe()
240 dev_err(&pdev->dev, "parent of node is missing?\n"); in twl6040_vibra_probe()
241 return -EINVAL; in twl6040_vibra_probe()
244 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in twl6040_vibra_probe()
247 dev_err(&pdev->dev, "couldn't allocate memory\n"); in twl6040_vibra_probe()
248 return -ENOMEM; in twl6040_vibra_probe()
251 info->dev = &pdev->dev; in twl6040_vibra_probe()
253 info->twl6040 = dev_get_drvdata(pdev->dev.parent); in twl6040_vibra_probe()
255 of_property_read_u32(twl6040_core_node, "ti,vibldrv-res", in twl6040_vibra_probe()
256 &info->vibldrv_res); in twl6040_vibra_probe()
257 of_property_read_u32(twl6040_core_node, "ti,vibrdrv-res", in twl6040_vibra_probe()
258 &info->vibrdrv_res); in twl6040_vibra_probe()
259 of_property_read_u32(twl6040_core_node, "ti,viblmotor-res", in twl6040_vibra_probe()
260 &info->viblmotor_res); in twl6040_vibra_probe()
261 of_property_read_u32(twl6040_core_node, "ti,vibrmotor-res", in twl6040_vibra_probe()
262 &info->vibrmotor_res); in twl6040_vibra_probe()
263 of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV", &vddvibl_uV); in twl6040_vibra_probe()
264 of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV", &vddvibr_uV); in twl6040_vibra_probe()
268 if ((!info->vibldrv_res && !info->viblmotor_res) || in twl6040_vibra_probe()
269 (!info->vibrdrv_res && !info->vibrmotor_res)) { in twl6040_vibra_probe()
270 dev_err(info->dev, "invalid vibra driver/motor resistance\n"); in twl6040_vibra_probe()
271 return -EINVAL; in twl6040_vibra_probe()
274 info->irq = platform_get_irq(pdev, 0); in twl6040_vibra_probe()
275 if (info->irq < 0) in twl6040_vibra_probe()
276 return -EINVAL; in twl6040_vibra_probe()
278 error = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in twl6040_vibra_probe()
283 dev_err(info->dev, "VIB IRQ request failed: %d\n", error); in twl6040_vibra_probe()
287 info->supplies[0].supply = "vddvibl"; in twl6040_vibra_probe()
288 info->supplies[1].supply = "vddvibr"; in twl6040_vibra_probe()
294 ARRAY_SIZE(info->supplies), in twl6040_vibra_probe()
295 info->supplies); in twl6040_vibra_probe()
297 dev_err(info->dev, "couldn't get regulators %d\n", error); in twl6040_vibra_probe()
302 error = regulator_set_voltage(info->supplies[0].consumer, in twl6040_vibra_probe()
305 dev_err(info->dev, "failed to set VDDVIBL volt %d\n", in twl6040_vibra_probe()
312 error = regulator_set_voltage(info->supplies[1].consumer, in twl6040_vibra_probe()
315 dev_err(info->dev, "failed to set VDDVIBR volt %d\n", in twl6040_vibra_probe()
321 INIT_WORK(&info->play_work, vibra_play_work); in twl6040_vibra_probe()
323 info->input_dev = devm_input_allocate_device(&pdev->dev); in twl6040_vibra_probe()
324 if (!info->input_dev) { in twl6040_vibra_probe()
325 dev_err(info->dev, "couldn't allocate input device\n"); in twl6040_vibra_probe()
326 return -ENOMEM; in twl6040_vibra_probe()
329 input_set_drvdata(info->input_dev, info); in twl6040_vibra_probe()
331 info->input_dev->name = "twl6040:vibrator"; in twl6040_vibra_probe()
332 info->input_dev->id.version = 1; in twl6040_vibra_probe()
333 info->input_dev->close = twl6040_vibra_close; in twl6040_vibra_probe()
334 __set_bit(FF_RUMBLE, info->input_dev->ffbit); in twl6040_vibra_probe()
336 error = input_ff_create_memless(info->input_dev, NULL, vibra_play); in twl6040_vibra_probe()
338 dev_err(info->dev, "couldn't register vibrator to FF\n"); in twl6040_vibra_probe()
342 error = input_register_device(info->input_dev); in twl6040_vibra_probe()
344 dev_err(info->dev, "couldn't register input device\n"); in twl6040_vibra_probe()
355 .driver = {
356 .name = "twl6040-vibra",
362 MODULE_ALIAS("platform:twl6040-vibra");
363 MODULE_DESCRIPTION("TWL6040 Vibra driver");