Lines Matching +full:pwm +full:- +full:vibrator
1 // SPDX-License-Identifier: GPL-2.0-only
3 * twl4030-vibra.c - TWL4030 Vibrator driver
5 * Copyright (C) 2008-2010 Nokia Corporation
9 * Input by Jari Vanhala <ext-jari.vanhala@nokia.com>
18 #include <linux/mfd/twl4030-audio.h>
26 #define EFFECT_DIR_180_DEG 0x8000 /* range is 0 - 0xFFFF */
45 /* Disable LEDA & LEDB, cannot be used with vibra (PWM) */ in vibra_disable_leds()
51 /* Powers H-Bridge and enables audio clk */
58 /* turn H-Bridge on */ in vibra_enable()
66 info->enabled = true; in vibra_enable()
73 /* Power down H-Bridge */ in vibra_disable()
82 info->enabled = false; in vibra_disable()
90 int pwm; in vibra_play_work() local
93 dir = info->direction; in vibra_play_work()
94 pwm = info->speed; in vibra_play_work()
98 if (pwm && (!info->coexist || !(reg & TWL4030_VIBRA_SEL))) { in vibra_play_work()
100 if (!info->enabled) in vibra_play_work()
111 /* set PWM, 1 = max, 255 = min */ in vibra_play_work()
113 256 - pwm, TWL4030_REG_VIBRA_SET); in vibra_play_work()
115 if (info->enabled) in vibra_play_work()
127 info->speed = effect->u.rumble.strong_magnitude >> 8; in vibra_play()
128 if (!info->speed) in vibra_play()
129 info->speed = effect->u.rumble.weak_magnitude >> 9; in vibra_play()
130 info->direction = effect->direction < EFFECT_DIR_180_DEG ? 0 : 1; in vibra_play()
131 schedule_work(&info->play_work); in vibra_play()
139 cancel_work_sync(&info->play_work); in twl4030_vibra_close()
141 if (info->enabled) in twl4030_vibra_close()
151 if (info->enabled) in twl4030_vibra_suspend()
181 struct device_node *twl4030_core_node = pdev->dev.parent->of_node; in twl4030_vibra_probe()
186 dev_dbg(&pdev->dev, "twl4030 OF node is missing\n"); in twl4030_vibra_probe()
187 return -EINVAL; in twl4030_vibra_probe()
190 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in twl4030_vibra_probe()
192 return -ENOMEM; in twl4030_vibra_probe()
194 info->dev = &pdev->dev; in twl4030_vibra_probe()
195 info->coexist = twl4030_vibra_check_coexist(twl4030_core_node); in twl4030_vibra_probe()
196 INIT_WORK(&info->play_work, vibra_play_work); in twl4030_vibra_probe()
198 info->input_dev = devm_input_allocate_device(&pdev->dev); in twl4030_vibra_probe()
199 if (info->input_dev == NULL) { in twl4030_vibra_probe()
200 dev_err(&pdev->dev, "couldn't allocate input device\n"); in twl4030_vibra_probe()
201 return -ENOMEM; in twl4030_vibra_probe()
204 input_set_drvdata(info->input_dev, info); in twl4030_vibra_probe()
206 info->input_dev->name = "twl4030:vibrator"; in twl4030_vibra_probe()
207 info->input_dev->id.version = 1; in twl4030_vibra_probe()
208 info->input_dev->close = twl4030_vibra_close; in twl4030_vibra_probe()
209 __set_bit(FF_RUMBLE, info->input_dev->ffbit); in twl4030_vibra_probe()
211 ret = input_ff_create_memless(info->input_dev, NULL, vibra_play); in twl4030_vibra_probe()
213 dev_dbg(&pdev->dev, "couldn't register vibrator to FF\n"); in twl4030_vibra_probe()
217 ret = input_register_device(info->input_dev); in twl4030_vibra_probe()
219 dev_dbg(&pdev->dev, "couldn't register input device\n"); in twl4030_vibra_probe()
229 input_ff_destroy(info->input_dev); in twl4030_vibra_probe()
236 .name = "twl4030-vibra",
242 MODULE_ALIAS("platform:twl4030-vibra");