Lines Matching +full:regulator +full:- +full:haptic

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Regulator haptic driver
13 #include <linux/platform_data/regulator-haptic.h>
15 #include <linux/regulator/consumer.h>
23 struct regulator *regulator; member
36 static int regulator_haptic_toggle(struct regulator_haptic *haptic, bool on) in regulator_haptic_toggle() argument
40 if (haptic->active != on) { in regulator_haptic_toggle()
42 error = on ? regulator_enable(haptic->regulator) : in regulator_haptic_toggle()
43 regulator_disable(haptic->regulator); in regulator_haptic_toggle()
45 dev_err(haptic->dev, in regulator_haptic_toggle()
46 "failed to switch regulator %s: %d\n", in regulator_haptic_toggle()
51 haptic->active = on; in regulator_haptic_toggle()
57 static int regulator_haptic_set_voltage(struct regulator_haptic *haptic, in regulator_haptic_set_voltage() argument
64 volt_mag_multi = (u64)(haptic->max_volt - haptic->min_volt) * magnitude; in regulator_haptic_set_voltage()
67 error = regulator_set_voltage(haptic->regulator, in regulator_haptic_set_voltage()
68 intensity + haptic->min_volt, in regulator_haptic_set_voltage()
69 haptic->max_volt); in regulator_haptic_set_voltage()
71 dev_err(haptic->dev, "cannot set regulator voltage to %d: %d\n", in regulator_haptic_set_voltage()
72 intensity + haptic->min_volt, error); in regulator_haptic_set_voltage()
76 regulator_haptic_toggle(haptic, !!magnitude); in regulator_haptic_set_voltage()
83 struct regulator_haptic *haptic = container_of(work, in regulator_haptic_work() local
86 guard(mutex)(&haptic->mutex); in regulator_haptic_work()
88 if (!haptic->suspended) in regulator_haptic_work()
89 regulator_haptic_set_voltage(haptic, haptic->magnitude); in regulator_haptic_work()
95 struct regulator_haptic *haptic = input_get_drvdata(input); in regulator_haptic_play_effect() local
97 haptic->magnitude = effect->u.rumble.strong_magnitude; in regulator_haptic_play_effect()
98 if (!haptic->magnitude) in regulator_haptic_play_effect()
99 haptic->magnitude = effect->u.rumble.weak_magnitude; in regulator_haptic_play_effect()
101 schedule_work(&haptic->work); in regulator_haptic_play_effect()
108 struct regulator_haptic *haptic = input_get_drvdata(input); in regulator_haptic_close() local
110 cancel_work_sync(&haptic->work); in regulator_haptic_close()
111 regulator_haptic_set_voltage(haptic, 0); in regulator_haptic_close()
115 regulator_haptic_parse_dt(struct device *dev, struct regulator_haptic *haptic) in regulator_haptic_parse_dt() argument
120 node = dev->of_node; in regulator_haptic_parse_dt()
123 return -EINVAL; in regulator_haptic_parse_dt()
126 error = of_property_read_u32(node, "max-microvolt", &haptic->max_volt); in regulator_haptic_parse_dt()
128 dev_err(dev, "cannot parse max-microvolt\n"); in regulator_haptic_parse_dt()
132 error = of_property_read_u32(node, "min-microvolt", &haptic->min_volt); in regulator_haptic_parse_dt()
134 dev_err(dev, "cannot parse min-microvolt\n"); in regulator_haptic_parse_dt()
143 const struct regulator_haptic_data *pdata = dev_get_platdata(&pdev->dev); in regulator_haptic_probe()
144 struct regulator_haptic *haptic; in regulator_haptic_probe() local
148 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL); in regulator_haptic_probe()
149 if (!haptic) in regulator_haptic_probe()
150 return -ENOMEM; in regulator_haptic_probe()
152 platform_set_drvdata(pdev, haptic); in regulator_haptic_probe()
153 haptic->dev = &pdev->dev; in regulator_haptic_probe()
154 mutex_init(&haptic->mutex); in regulator_haptic_probe()
155 INIT_WORK(&haptic->work, regulator_haptic_work); in regulator_haptic_probe()
158 haptic->max_volt = pdata->max_volt; in regulator_haptic_probe()
159 haptic->min_volt = pdata->min_volt; in regulator_haptic_probe()
161 error = regulator_haptic_parse_dt(&pdev->dev, haptic); in regulator_haptic_probe()
165 dev_err(&pdev->dev, "Missing platform data\n"); in regulator_haptic_probe()
166 return -EINVAL; in regulator_haptic_probe()
169 haptic->regulator = devm_regulator_get_exclusive(&pdev->dev, "haptic"); in regulator_haptic_probe()
170 if (IS_ERR(haptic->regulator)) { in regulator_haptic_probe()
171 dev_err(&pdev->dev, "failed to get regulator\n"); in regulator_haptic_probe()
172 return PTR_ERR(haptic->regulator); in regulator_haptic_probe()
175 input_dev = devm_input_allocate_device(&pdev->dev); in regulator_haptic_probe()
177 return -ENOMEM; in regulator_haptic_probe()
179 haptic->input_dev = input_dev; in regulator_haptic_probe()
180 haptic->input_dev->name = "regulator-haptic"; in regulator_haptic_probe()
181 haptic->input_dev->dev.parent = &pdev->dev; in regulator_haptic_probe()
182 haptic->input_dev->close = regulator_haptic_close; in regulator_haptic_probe()
183 input_set_drvdata(haptic->input_dev, haptic); in regulator_haptic_probe()
184 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE); in regulator_haptic_probe()
189 dev_err(&pdev->dev, "failed to create force-feedback\n"); in regulator_haptic_probe()
193 error = input_register_device(haptic->input_dev); in regulator_haptic_probe()
195 dev_err(&pdev->dev, "failed to register input device\n"); in regulator_haptic_probe()
205 struct regulator_haptic *haptic = platform_get_drvdata(pdev); in regulator_haptic_suspend() local
207 scoped_guard(mutex_intr, &haptic->mutex) { in regulator_haptic_suspend()
208 regulator_haptic_set_voltage(haptic, 0); in regulator_haptic_suspend()
209 haptic->suspended = true; in regulator_haptic_suspend()
214 return -EINTR; in regulator_haptic_suspend()
220 struct regulator_haptic *haptic = platform_get_drvdata(pdev); in regulator_haptic_resume() local
223 guard(mutex)(&haptic->mutex); in regulator_haptic_resume()
225 haptic->suspended = false; in regulator_haptic_resume()
227 magnitude = READ_ONCE(haptic->magnitude); in regulator_haptic_resume()
229 regulator_haptic_set_voltage(haptic, magnitude); in regulator_haptic_resume()
238 { .compatible = "regulator-haptic" },
246 .name = "regulator-haptic",
255 MODULE_DESCRIPTION("Regulator haptic driver");