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()
231 struct device *twl6040_core_dev = pdev->dev.parent; in twl6040_vibra_probe()
238 of_get_child_by_name(twl6040_core_dev->of_node, "vibra"); 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()
246 dev_err(&pdev->dev, "couldn't allocate memory\n"); in twl6040_vibra_probe()
247 return -ENOMEM; in twl6040_vibra_probe()
250 info->dev = &pdev->dev; in twl6040_vibra_probe()
252 info->twl6040 = dev_get_drvdata(pdev->dev.parent); in twl6040_vibra_probe()
254 of_property_read_u32(twl6040_core_node, "ti,vibldrv-res", in twl6040_vibra_probe()
255 &info->vibldrv_res); in twl6040_vibra_probe()
256 of_property_read_u32(twl6040_core_node, "ti,vibrdrv-res", in twl6040_vibra_probe()
257 &info->vibrdrv_res); in twl6040_vibra_probe()
258 of_property_read_u32(twl6040_core_node, "ti,viblmotor-res", in twl6040_vibra_probe()
259 &info->viblmotor_res); in twl6040_vibra_probe()
260 of_property_read_u32(twl6040_core_node, "ti,vibrmotor-res", in twl6040_vibra_probe()
261 &info->vibrmotor_res); in twl6040_vibra_probe()
262 of_property_read_u32(twl6040_core_node, "ti,vddvibl-uV", &vddvibl_uV); in twl6040_vibra_probe()
263 of_property_read_u32(twl6040_core_node, "ti,vddvibr-uV", &vddvibr_uV); in twl6040_vibra_probe()
265 if ((!info->vibldrv_res && !info->viblmotor_res) || in twl6040_vibra_probe()
266 (!info->vibrdrv_res && !info->vibrmotor_res)) { in twl6040_vibra_probe()
267 dev_err(info->dev, "invalid vibra driver/motor resistance\n"); in twl6040_vibra_probe()
268 return -EINVAL; in twl6040_vibra_probe()
271 info->irq = platform_get_irq(pdev, 0); in twl6040_vibra_probe()
272 if (info->irq < 0) in twl6040_vibra_probe()
273 return -EINVAL; in twl6040_vibra_probe()
275 error = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, in twl6040_vibra_probe()
280 dev_err(info->dev, "VIB IRQ request failed: %d\n", error); in twl6040_vibra_probe()
284 info->supplies[0].supply = "vddvibl"; in twl6040_vibra_probe()
285 info->supplies[1].supply = "vddvibr"; in twl6040_vibra_probe()
291 ARRAY_SIZE(info->supplies), in twl6040_vibra_probe()
292 info->supplies); in twl6040_vibra_probe()
294 dev_err(info->dev, "couldn't get regulators %d\n", error); in twl6040_vibra_probe()
299 error = regulator_set_voltage(info->supplies[0].consumer, in twl6040_vibra_probe()
302 dev_err(info->dev, "failed to set VDDVIBL volt %d\n", in twl6040_vibra_probe()
309 error = regulator_set_voltage(info->supplies[1].consumer, in twl6040_vibra_probe()
312 dev_err(info->dev, "failed to set VDDVIBR volt %d\n", in twl6040_vibra_probe()
318 INIT_WORK(&info->play_work, vibra_play_work); in twl6040_vibra_probe()
320 info->input_dev = devm_input_allocate_device(&pdev->dev); in twl6040_vibra_probe()
321 if (!info->input_dev) { in twl6040_vibra_probe()
322 dev_err(info->dev, "couldn't allocate input device\n"); in twl6040_vibra_probe()
323 return -ENOMEM; in twl6040_vibra_probe()
326 input_set_drvdata(info->input_dev, info); in twl6040_vibra_probe()
328 info->input_dev->name = "twl6040:vibrator"; in twl6040_vibra_probe()
329 info->input_dev->id.version = 1; in twl6040_vibra_probe()
330 info->input_dev->close = twl6040_vibra_close; in twl6040_vibra_probe()
331 __set_bit(FF_RUMBLE, info->input_dev->ffbit); in twl6040_vibra_probe()
333 error = input_ff_create_memless(info->input_dev, NULL, vibra_play); in twl6040_vibra_probe()
335 dev_err(info->dev, "couldn't register vibrator to FF\n"); in twl6040_vibra_probe()
339 error = input_register_device(info->input_dev); in twl6040_vibra_probe()
341 dev_err(info->dev, "couldn't register input device\n"); in twl6040_vibra_probe()
352 .driver = {
353 .name = "twl6040-vibra",
359 MODULE_ALIAS("platform:twl6040-vibra");
360 MODULE_DESCRIPTION("TWL6040 Vibra driver");