28 #include <linux/module.h>
32 #include <linux/input.h>
34 #include <linux/slab.h>
38 #define EFFECT_DIR_180_DEG 0x8000
41 #define TWL6040_VIBRA_MOD 85
43 #define TWL6040_NUM_SUPPLIES 2
76 dev_warn(info->
dev,
"Left Vibrator overcurrent detected\n");
81 dev_warn(info->
dev,
"Right Vibrator overcurrent detected\n");
89 static void twl6040_vibra_enable(
struct vibra_info *info)
91 struct twl6040 *twl6040 = info->
twl6040;
96 dev_err(info->
dev,
"failed to enable regulators %d\n", ret);
122 static void twl6040_vibra_disable(
struct vibra_info *info)
124 struct twl6040 *twl6040 = info->
twl6040;
135 static u8 twl6040_vibra_code(
int vddvib,
int vibdrv_res,
int motor_res,
143 (100 * (vibdrv_res + motor_res));
159 static void twl6040_vibra_set_effect(
struct vibra_info *info)
161 struct twl6040 *twl6040 = info->
twl6040;
167 vibdatl = twl6040_vibra_code(volt, info->
vibldrv_res,
173 vibdatr = twl6040_vibra_code(volt, info->
vibrdrv_res,
190 twl6040_vibra_enable(info);
192 twl6040_vibra_set_effect(info);
194 twl6040_vibra_disable(info);
202 struct vibra_info *info = input_get_drvdata(input);
208 dev_info(&input->dev,
"Vibra is configured for audio\n");
218 dev_info(&input->dev,
"work is already on queue\n");
225 static void twl6040_vibra_close(
struct input_dev *input)
227 struct vibra_info *info = input_get_drvdata(input);
234 twl6040_vibra_disable(info);
239 #ifdef CONFIG_PM_SLEEP
240 static int twl6040_vibra_suspend(
struct device *
dev)
243 struct vibra_info *info = platform_get_drvdata(pdev);
248 twl6040_vibra_disable(info);
261 struct device *twl6040_core_dev = pdev->
dev.parent;
273 if (!pdata && !twl6040_core_node) {
274 dev_err(&pdev->
dev,
"platform_data not available\n");
280 dev_err(&pdev->
dev,
"couldn't allocate memory\n");
295 of_property_read_u32(twl6040_core_node,
"ti,vibldrv-res",
297 of_property_read_u32(twl6040_core_node,
"ti,vibrdrv-res",
299 of_property_read_u32(twl6040_core_node,
"ti,viblmotor-res",
301 of_property_read_u32(twl6040_core_node,
"ti,vibrmotor-res",
303 of_property_read_u32(twl6040_core_node,
"ti,vddvibl-uV",
305 of_property_read_u32(twl6040_core_node,
"ti,vddvibr-uV",
311 dev_err(info->
dev,
"invalid vibra driver/motor resistance\n");
325 info->
input_dev = input_allocate_device();
327 dev_err(info->
dev,
"couldn't allocate input device\n");
332 input_set_drvdata(info->
input_dev, info);
334 info->
input_dev->name =
"twl6040:vibrator";
337 info->
input_dev->close = twl6040_vibra_close;
342 dev_err(info->
dev,
"couldn't register vibrator to FF\n");
346 ret = input_register_device(info->
input_dev);
348 dev_err(info->
dev,
"couldn't register input device\n");
352 platform_set_drvdata(pdev, info);
355 "twl6040_irq_vib", info);
357 dev_err(info->
dev,
"VIB IRQ request failed: %d\n", ret);
361 info->
supplies[0].supply =
"vddvibl";
362 info->
supplies[1].supply =
"vddvibr";
370 dev_err(info->
dev,
"couldn't get regulators %d\n", ret);
376 vddvibl_uV, vddvibl_uV);
378 dev_err(info->
dev,
"failed to set VDDVIBL volt %d\n",
386 vddvibr_uV, vddvibr_uV);
388 dev_err(info->
dev,
"failed to set VDDVIBR volt %d\n",
396 dev_err(info->
dev,
"couldn't create workqueue\n");
409 input_unregister_device(info->
input_dev);
423 struct vibra_info *info = platform_get_drvdata(pdev);
425 input_unregister_device(info->
input_dev);
435 .probe = twl6040_vibra_probe,
438 .name =
"twl6040-vibra",
440 .pm = &twl6040_vibra_pm_ops,